home *** CD-ROM | disk | FTP | other *** search
/ Clickx 75 / Clickx 75.iso / software / expressionweb / expressionwebv3 / ExpressionWeb_en.exe / Setup / WeNoLoc.cab / xweb.StaticFiles.CAML2XSL.XSL < prev    next >
Encoding:
Extensible Markup Language  |  2009-06-11  |  162.5 KB  |  3,612 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet 
  3.     version="1.0" 
  4.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  5.     xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  6.     xmlns:xz="urn:frontpage:ddw:xsltgen"
  7.     xmlns:out="urn:frontpage:ddw:xsltout"
  8.     xmlns:SharePoint="Microsoft.SharePoint.WebControls"
  9.     xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
  10.     xmlns:asp="http://schemas.microsoft.com/ASPNET/20" 
  11.     xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
  12.  
  13.     <xsl:param name="fldTypes" select="document('fldtypes.xml')"/>
  14.     <xsl:param name="viewName">{76853A94-4A67-4336-AF12-9C751A25AEA1}</xsl:param>
  15.     <xsl:param name="formType">EditForm</xsl:param>
  16.     <xsl:param name="isAViewAndNotAForm">1</xsl:param>
  17.     <xsl:param name="isThreaded"></xsl:param>
  18.     <xsl:param name="FreeForm">0</xsl:param>
  19.     <xsl:param name="resultRoot">Rows</xsl:param>
  20.     <xsl:param name="resultRow">Row</xsl:param>
  21.     <xsl:param name="singleQuote">'</xsl:param>
  22.     <xsl:param name="codeReduced">1</xsl:param>
  23.     <xsl:param name="Counter">99</xsl:param>
  24.     
  25.     <xsl:variable name="generalDisplayPattern">
  26.         <xsl:choose>
  27.             <xsl:when test="$isAViewAndNotAForm = '1' ">DisplayPattern</xsl:when>
  28.             <xsl:when test="$formType = 'DisplayForm'">DisplayPattern</xsl:when>
  29.             <xsl:otherwise>EditPattern</xsl:otherwise>
  30.         </xsl:choose>
  31.     </xsl:variable>
  32.  
  33.     <xsl:namespace-alias stylesheet-prefix="xz" result-prefix="xsl"/>
  34.     <xsl:namespace-alias stylesheet-prefix="out" result-prefix="msxsl"/>
  35.  
  36.     <xsl:template match="/">
  37.         <xsl:text disable-output-escaping="yes">
  38.             <![CDATA[ <!DOCTYPE camlxsl [<!ENTITY nbsp " ">]> ]]>
  39.         </xsl:text>
  40.         <xsl:choose>
  41.             <xsl:when test="$isAViewAndNotAForm = '1'">
  42.                 <xsl:apply-templates select="//View[@Name=$viewName or not(@Name)]"/>
  43.             </xsl:when>
  44.             <xsl:otherwise>
  45.                 <xsl:apply-templates select="//Form[@Type=$formType]"/>
  46.             </xsl:otherwise>
  47.         </xsl:choose>
  48.     </xsl:template>
  49.     
  50. <!-- here be view stuff -->
  51.     <xsl:template match="View">
  52.         <xz:stylesheet version="1.0" 
  53.             xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  54.             xmlns:o="urn:schemas-microsoft-com:office"
  55.             xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" 
  56.             xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 
  57.             xmlns:rs="urn:schemas-microsoft-com:rowset" 
  58.             xmlns:z="#RowsetSchema"
  59.             xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
  60.             xmlns:SharePoint="Microsoft.SharePoint.WebControls"
  61.             xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
  62.             xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
  63.             exclude-result-prefixes="rs z o s ddwrt dt msxsl">
  64.  
  65.             <xz:output method="html" indent="no"/>
  66.             <xz:decimal-format NaN=""/>
  67.  
  68.              <xsl:call-template name="genParams">
  69.             </xsl:call-template>
  70.                             
  71.             <xsl:apply-templates select=".//*" mode="genParams">
  72.                 <xsl:with-param name="currentList" select="."/>
  73.                 <xsl:with-param name="viewNode" select="."/>
  74.                 <xsl:sort select="name()"/>
  75.             </xsl:apply-templates>
  76.  
  77.             <xsl:apply-templates select=".//Length|.//FieldSwitch" mode="genVariables">
  78.                 <xsl:with-param name="currentView" select="."/>
  79.             </xsl:apply-templates>
  80.  
  81.             <!-- look in the head fields for more params -->
  82.             <!-- url node without attributes will be ddwrt which is context sensitive, it won't be processed here
  83.                    Instead it'll be processed on per field basis-->
  84.             <xsl:apply-templates select="/List/MetaData/Fields//*[not(name(.) = 'URL' and not( @*))]" mode="genParams">
  85.                 <xsl:with-param name="currentList" select="/List/MetaData/Fields"/>
  86.                 <xsl:with-param name="viewNode" select="."/>
  87.             </xsl:apply-templates>
  88.  
  89.             <!-- we also need to look at url:lookup in the fldtypes.xml file,
  90.                   be more specific to avoid duplication.-->
  91.             <xsl:apply-templates select="$fldTypes//URL" mode="genParams">
  92.                 <xsl:with-param name="currentList" select="$fldTypes"/>
  93.                 <xsl:with-param name="viewNode" select="."/>
  94.             </xsl:apply-templates>            
  95.  
  96.             <!-- come back here -->
  97.             <xsl:variable name="renderPatternName">DisplayPattern</xsl:variable>
  98.  
  99.              <xsl:call-template name="addScript">
  100.             </xsl:call-template>
  101.  
  102.             <xsl:apply-templates select="." mode="genRootTemplate">
  103.                 <xsl:with-param name="currentView" select="."/>
  104.             </xsl:apply-templates>
  105.  
  106.             <xsl:apply-templates select="ViewBody" mode="genTemplates">
  107.                 <xsl:with-param name="currentView" select="."/>
  108.                 <xsl:with-param name="renderPattern" select="$renderPatternName"/>
  109.                 <xsl:with-param name="fieldData" select="."/>
  110.                 <xsl:with-param name="Field" select="."/>            
  111.             </xsl:apply-templates>
  112.  
  113.             <!--<xsl:apply-templates select="GroupByHeader" mode="genTemplates">
  114.                 <xsl:with-param name="currentView" select="."/>
  115.                 <xsl:with-param name="renderPattern" select="$renderPatternName"/>
  116.                 <xsl:with-param name="fieldData" select="."/>
  117.                 <xsl:with-param name="Field" select="."/>            
  118.             </xsl:apply-templates>
  119.             
  120.             <xsl:apply-templates select="GroupByFooter" mode="genTemplates">
  121.                 <xsl:with-param name="currentView" select="."/>
  122.                 <xsl:with-param name="renderPattern" select="$renderPatternName"/>
  123.                 <xsl:with-param name="fieldData" select="."/>
  124.                 <xsl:with-param name="Field" select="."/>            
  125.             </xsl:apply-templates>-->
  126.             
  127.             <xsl:call-template name="GenStringFunction"/>
  128.             
  129.             <xsl:apply-templates select="Toolbar" mode="genTemplates">
  130.                     <xsl:with-param name="currentView" select="."/>
  131.                     <xsl:with-param name="fieldData" select="."/>
  132.                     <xsl:with-param name="renderPattern" select="'HeaderPattern'"/>
  133.                     <xsl:with-param name="Field" select="."/>                        
  134.             </xsl:apply-templates>
  135.             
  136.         </xz:stylesheet>
  137.     </xsl:template>
  138. <!-- end of view stuff -->
  139.  
  140. <!-- here be form stuff -->
  141.     <xsl:template match="Form">
  142.         <xz:stylesheet version="1.0" 
  143.             xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  144.             xmlns:o="urn:schemas-microsoft-com:office"
  145.             xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" 
  146.             xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 
  147.             xmlns:rs="urn:schemas-microsoft-com:rowset" 
  148.             xmlns:z="#RowsetSchema"
  149.             xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
  150.  
  151.             <!-- come back here -->
  152.             <xsl:variable name="renderPatternName">
  153.                 <xsl:choose>
  154.                     <xsl:when test="@Type = 'EditForm'">EditPattern</xsl:when>
  155.                     <xsl:when test="@Type = 'NewForm'">NewPattern</xsl:when>
  156.                     <xsl:when test="@Type = 'DisplayForm'">DisplayPattern</xsl:when>
  157.                     <xsl:otherwise>DisplayPattern</xsl:otherwise>
  158.                 </xsl:choose>
  159.             </xsl:variable>
  160.             
  161.              <xsl:call-template name="genParams">
  162.             </xsl:call-template>
  163.  
  164.             <xsl:apply-templates select=".//*" mode="genParams">
  165.                 <xsl:with-param name="currentList" select="."/>
  166.                 <xsl:with-param name="viewNode" select="."/>                
  167.                 <xsl:sort select="name()"/>
  168.             </xsl:apply-templates>
  169.         
  170.             <!-- we also need to look at url:lookup in the fldtypes.xml file-->
  171.             <xsl:apply-templates select="$fldTypes//URL" mode="genParams">
  172.                 <xsl:with-param name="currentList" select="$fldTypes"/>
  173.                 <xsl:with-param name="viewNode" select="."/>                
  174.             </xsl:apply-templates>            
  175.  
  176.             <xsl:apply-templates select="$fldTypes//RenderPattern[@Name = $renderPatternName]//Switch | .//Switch" mode="genVariables">
  177.                 <xsl:with-param name="currentView" select="."/>
  178.                 <xsl:with-param name="renderPattern" select="$renderPatternName"/>
  179.                 <xsl:with-param name="fieldData" select="."/>
  180.             </xsl:apply-templates>
  181.  
  182.              <xsl:call-template name="addScript">
  183.             </xsl:call-template>
  184.             
  185.             <xsl:apply-templates select="." mode="genRootTemplate">
  186.                 <xsl:with-param name="currentView" select="."/>
  187.             </xsl:apply-templates>
  188.             
  189.             <xsl:apply-templates select="ListFormBody" mode="genTemplates">
  190.                 <xsl:with-param name="currentView" select="."/>
  191.                 <xsl:with-param name="renderPattern" select="$renderPatternName"/>
  192.                 <xsl:with-param name="fieldData" select="."/>
  193.                 <xsl:with-param name="Field" select="."/>                            
  194.             </xsl:apply-templates>
  195.         </xz:stylesheet>
  196.     </xsl:template>
  197. <!-- end of form stuff -->
  198.  
  199.     <!-- generate params that are common to all pages, like PageUrl, list name, etc-->
  200.     <xsl:template name="genParams">
  201.         <xz:param>
  202.             <xsl:attribute name="name">PageUrl</xsl:attribute>
  203.         </xz:param>
  204.         
  205.         <xz:param>
  206.             <xsl:attribute name="name">PagePath</xsl:attribute>
  207.         </xz:param>
  208.  
  209.         <xz:param>
  210.             <xsl:attribute name="name">HttpHost</xsl:attribute>
  211.         </xz:param>
  212.  
  213.         <xz:param>
  214.             <xsl:attribute name="name">HttpPath</xsl:attribute>
  215.         </xz:param>
  216.  
  217.         <xz:param>
  218.             <xsl:attribute name="name">List</xsl:attribute>
  219.         </xz:param>
  220.         
  221.         <xz:param>
  222.             <xsl:attribute name="name">URL_Display</xsl:attribute>
  223.         </xz:param>
  224.  
  225.         <xz:param>
  226.             <xsl:attribute name="name">HttpVDir</xsl:attribute>
  227.         </xz:param>
  228.  
  229.         <xz:param>
  230.             <xsl:attribute name="name">View</xsl:attribute>
  231.         </xz:param>
  232.  
  233.         <xz:param>
  234.             <xsl:attribute name="name">FilterLink</xsl:attribute>
  235.             <xsl:attribute name="select">ddwrt:FilterLink()</xsl:attribute>
  236.         </xz:param>
  237.  
  238.         <xsl:if test="$isThreaded">
  239.             <xz:param name="isThreaded">TRUE</xz:param>
  240.         </xsl:if>
  241.  
  242.         <xz:param name="Language">1033</xz:param>
  243.         <xz:param name="dvt_adhocmode">sort</xz:param>
  244.         <xz:param name="dvt_adhocfiltermode">xsl</xz:param>
  245.         <xz:param name="dvt_fieldsort">1</xz:param>
  246.         <xz:param name="dvt_sortfield"></xz:param>
  247.         <xz:param name="dvt_groupfield"></xz:param>
  248.         <xz:param name="dvt_groupdisplay"></xz:param>
  249.         <xz:param name="dvt_sortdir"></xz:param>
  250.         <xz:param name="dvt_groupdir"></xz:param>
  251.         <xz:param name="dvt_filterfield"></xz:param>
  252.         <xz:param name="dvt_filterval"></xz:param>
  253.         <xz:param name="dvt_filtertype"></xz:param>
  254.         <xz:param name="dvt_firstrow">1</xz:param>
  255.         <xz:param name="dvt_p2plinkfields"></xz:param>
  256.         <xz:param name="dvt_nextpagedata"></xz:param>
  257.         <xz:param name="dvt_grouptype"></xz:param>
  258.         <xz:param name="dvt_sorttype"></xz:param>
  259.         <xz:param name="dvt_groupsorttype"></xz:param>
  260.         <xz:param name="dvt_apos">'</xz:param>
  261.         <xz:param name="filterParam" ddwrt:NoCAMLVariable="1"></xz:param>        
  262.         <xz:param name="ImagesPath"></xz:param>
  263.         <xz:param name="ListUrlDir"></xz:param>
  264.         <xz:param name="EMail">EMail</xz:param>
  265.         <xz:param name="Userid"></xz:param>
  266.  
  267.         <xsl:if test="$codeReduced='1'">
  268.             <xz:variable name="dvt_1_automode">0</xz:variable>
  269.         </xsl:if>
  270.  
  271.     </xsl:template>
  272.  
  273.     <!-- this is the stuff for adding script in ddrwt run time -->
  274.     <xsl:template name="addScript">
  275.     </xsl:template>
  276.  
  277.     <xsl:template name="GenStringFunction">
  278.         <xz:template name="stringreplace">
  279.             <xz:param name="stringvalue"/>
  280.             <xz:param name="from"/>
  281.             <xz:param name="to"/>
  282.             
  283.             <xz:choose> 
  284.                 <xz:when test="contains($stringvalue, $from)">
  285.                     <xz:value-of>
  286.                         <xsl:attribute name="select">substring-before($stringvalue, $from)</xsl:attribute>
  287.                     </xz:value-of>
  288.                     <xz:if test="contains(substring($stringvalue, 1, string-length($stringvalue) - 1), $from)">
  289.                         <xz:value-of>
  290.                             <xsl:attribute name="select">$to</xsl:attribute>
  291.                         </xz:value-of>
  292.                         <xz:call-template name="stringreplace">
  293.                             <xz:with-param name="stringvalue">
  294.                                 <xsl:attribute name="select">substring-after($stringvalue, $from)</xsl:attribute>
  295.                             </xz:with-param>
  296.                             <xz:with-param name="from">
  297.                                 <xsl:attribute name="select">$from</xsl:attribute>
  298.                             </xz:with-param>
  299.                             <xz:with-param name="to">
  300.                                 <xsl:attribute name="select">$to</xsl:attribute>
  301.                             </xz:with-param>
  302.                         </xz:call-template>
  303.                     </xz:if>
  304.                 </xz:when>
  305.                 <xz:otherwise>
  306.                     <xz:value-of>
  307.                         <xsl:attribute name="select">$stringvalue</xsl:attribute>
  308.                     </xz:value-of>
  309.                 </xz:otherwise>
  310.             </xz:choose>
  311.         </xz:template>
  312.     </xsl:template>
  313.     
  314.     <!-- this is the stuff for generating the many params at the top
  315.         of the output stylesheet -->
  316.     <xsl:template match="*" mode="genParams"/>
  317.     
  318.     <xsl:template match="ID|Identity|WebQueryInfo" mode="genParams">
  319.         <!-- only one -->        
  320.         <xsl:param name="currentList"/>
  321.         <xsl:param name="viewNode"/>
  322.         
  323.          <xsl:call-template name="genParamTag">
  324.             <xsl:with-param name="currentness2" select="$currentList"/>
  325.             <xsl:with-param name="nodeness" select="."/>
  326.             <xsl:with-param name="viewNode" select="$viewNode"/>
  327.         </xsl:call-template>
  328.     </xsl:template>
  329.         
  330.      <!-- generate variables in the header of the view files
  331.             to get rid of the annoying "alt=switch" problem.    -->
  332.     <xsl:template match="Switch|FieldSwitch" mode="genVariables">
  333.         <xsl:param name="currentView"/>
  334.         <xsl:param name="fieldData"/>
  335.         <xsl:param name="renderPattern"/>
  336.  
  337.         <xsl:variable name="expr" select="Expr"/>
  338.         <xsl:variable name="Str" select="string(preceding-sibling::*[1])"/>
  339.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  340.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  341.  
  342.         <!-- if the previous nodes are "fieldsortimageURL" or the previous node is html node
  343.               that ends with " or ' or =, we'll do special add the special handlding code to have var first,
  344.               then directly call the var in the usage-->
  345.         <xsl:if test="name(preceding-sibling::*[2]) = 'FieldSortImageURL' or 
  346.                 (name($prevNode) = 'HTML' and (substring($prevStr, string-length($prevStr), 1) = '"'  
  347.                 or substring($prevStr, string-length($prevStr), 1) = $singleQuote and not(substring($Str, string-length($Str), 1) = ' '))) or (name($prevNode) = 'HTML' and (substring($prevStr, string-length($prevStr), 1) = $singleQuote or 
  348. substring($prevStr, string-length($prevStr), 1) = '='))">
  349.             <xz:variable>
  350.                 <xsl:attribute name="name"><xsl:value-of select="generate-id(.)"/></xsl:attribute>
  351.                     <xz:choose>
  352.                     <xsl:for-each select="Case">
  353.                         <xz:when>
  354.                             <xsl:attribute name="test">
  355.                                 <xsl:apply-templates mode="genTemplates" select="$expr/*">
  356.                                     <xsl:with-param name="currentView" select ="$currentView"/>
  357.                                     <xsl:with-param name="fieldData" select="$fieldData"/>
  358.                                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  359.                                 </xsl:apply-templates>='<xsl:value-of select="@Value"/>'</xsl:attribute>
  360.                                 
  361.                             <xsl:apply-templates mode="genTemplates" select="*">
  362.                                 <xsl:with-param name="currentView" select="$currentView"/>
  363.                                 <xsl:with-param name="fieldData" select="."/>
  364.                                 <xsl:with-param name="renderPattern" select="."/>
  365.                                 <xsl:with-param name="Field" select="."/>
  366.                             </xsl:apply-templates>    
  367.                         </xz:when>
  368.                     </xsl:for-each>
  369.                     <xsl:for-each select="Default">
  370.                         <xz:otherwise>
  371.                             <xsl:apply-templates mode="genTemplates" select="*">
  372.                                 <xsl:with-param name="currentView" select="$currentView"/>
  373.                                 <xsl:with-param name="fieldData" select="."/>
  374.                                 <xsl:with-param name="renderPattern" select="."/>
  375.                                 <xsl:with-param name="Field" select="."/>
  376.                             </xsl:apply-templates>
  377.                         </xz:otherwise>
  378.                     </xsl:for-each>
  379.                     </xz:choose>
  380.             </xz:variable>
  381.         </xsl:if>
  382.     </xsl:template>
  383.  
  384.      <!-- generate variables before the fields -->
  385.     <xsl:template match="Switch|FieldSwitch" mode="genVariablesInField">
  386.         <xsl:param name="currentView"/>
  387.         <xsl:param name="fieldData"/>
  388.         <xsl:param name="realFieldData"/>
  389.         <xsl:param name="renderPattern"/>
  390.  
  391.         <xsl:variable name="expr" select="Expr"/>
  392.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  393.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  394.  
  395.         <!-- if the previous nodes are "fieldsortimageURL" or the previous node is html node
  396.               that ends with " or ' or =, we'll do special add the special handlding code to have var first,
  397.               then directly call the var in the usage-->
  398.         <xsl:if test="name(preceding-sibling::*[1])='ImagesPath' or (name($prevNode) = 'HTML' and (substring($prevStr, string-length($prevStr), 1) = '"' 
  399.                             or substring($prevStr, string-length($prevStr), 1) = '=') or substring($prevStr, string-length($prevStr)-6, 7)='images/')
  400.                             or (name(ancestor::*[1])='ViewBody' and not(preceding-sibling::*[1]))">
  401.             <xz:variable>
  402.                 <xsl:attribute name="name"><xsl:value-of select="generate-id(.)"/></xsl:attribute>
  403.                     <xz:choose>
  404.                     <xsl:for-each select="Case">
  405.                         <xz:when>
  406.                             <xsl:attribute name="test">
  407.                                 <xsl:apply-templates mode="genTemplates" select="$expr/*">
  408.                                     <xsl:with-param name="currentView" select ="$currentView"/>
  409.                                     <xsl:with-param name="fieldData" select="$fieldData"/>
  410.                                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  411.                                 </xsl:apply-templates>='<xsl:value-of select="@Value"/>'</xsl:attribute>
  412.                                 
  413.                             <xsl:apply-templates mode="genTemplates" select="child::node()">
  414.                                 <xsl:with-param name="currentView" select="$currentView"/>
  415.                                 <xsl:with-param name="fieldData" select="$fieldData"/>
  416.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  417.                                 <xsl:with-param name="Field" select="."/>
  418.                             </xsl:apply-templates>    
  419.                         </xz:when>
  420.                     </xsl:for-each>
  421.                     <xsl:for-each select="Default">
  422.                         <xz:otherwise>
  423.                             <xsl:apply-templates mode="genTemplates" select="child::node()">
  424.                                 <xsl:with-param name="currentView" select="$currentView"/>
  425.                                 <xsl:with-param name="fieldData" select="$fieldData"/>
  426.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  427.                                 <xsl:with-param name="Field" select="."/>
  428.                             </xsl:apply-templates>
  429.                         </xz:otherwise>
  430.                     </xsl:for-each>
  431.                     </xz:choose>
  432.             </xz:variable>
  433.         </xsl:if>
  434.     </xsl:template>
  435.  
  436.     <!-- generate variables before the fields -->
  437.     <xsl:template match="LookupColumn" mode="genVariablesInField">
  438.         <xsl:param name="currentView"/>
  439.         <xsl:param name="fieldData"/>
  440.         <xsl:param name="realFieldData"/>
  441.         <xsl:param name="renderPattern"/>
  442.  
  443.         <xsl:variable name="expr" select="Expr"/>
  444.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  445.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  446.  
  447.         <xsl:if test="@ShowField and not(@ShowField='EMail')">
  448.             <xz:variable>
  449.                 <xsl:attribute name="name">UserLookup<xsl:value-of select="generate-id($realFieldData)"/><xsl:value-of select="generate-id(.)"/></xsl:attribute>
  450.                 <xsl:attribute name="select">ddwrt:UserLookup(string(@<xsl:value-of select='$realFieldData/@Name'/>), '<xsl:value-of select="@ShowField"/>')</xsl:attribute>
  451.             </xz:variable>            
  452.         </xsl:if>
  453.     </xsl:template>
  454.     
  455.      <!-- generate variables in the header of the view files
  456.             to get rid of the annoying "path=<MapToIcon>" problem.    -->
  457.     <xsl:template match="MapToIcon" mode="genVariables">
  458.         <xsl:param name="currentView"/>
  459.         <xsl:variable name="expr" select="Expr"/>
  460.     
  461.         <xz:variable>
  462.             <xsl:attribute name="name">MapToIcon<xsl:value-of select="generate-id(.)"/></xsl:attribute>
  463.             <xsl:attribute name="select">ddwrt:MapToIcon(<xsl:for-each select="Column">string('<xsl:value-of select="@Name"/>')<xsl:if test="not (position() = last())">,</xsl:if></xsl:for-each>)</xsl:attribute>
  464.         </xz:variable>
  465.     </xsl:template>    
  466.  
  467.      <!-- generate variables in the header of the view files
  468.             to get rid of the annoying "width=length()" problem.    -->
  469.     <xsl:template match="Length" mode="genVariables">
  470.         <xsl:param name="currentView"/>
  471.         <xsl:variable name="expr" select="Expr"/>
  472.  
  473.         <xz:variable>
  474.             <xsl:attribute name="name">curString<xsl:value-of select="generate-id(.)"/></xsl:attribute>
  475.             <xsl:attribute name="select">
  476.                 <xsl:apply-templates mode="genTemplates" select="*">
  477.                 <xsl:with-param name="currentView" select="$currentView"/>
  478.                 <xsl:with-param name="fieldData" select="."/>
  479.                 <xsl:with-param name="renderPattern" select="."/>
  480.                 <xsl:with-param name="Field" select="."/>                        
  481.                 </xsl:apply-templates>
  482.             </xsl:attribute>
  483.         </xz:variable>
  484.         
  485.         <xz:variable>    
  486.             <xsl:attribute name="name">Length<xsl:value-of select="generate-id(.)"/></xsl:attribute>
  487.             <xsl:attribute name="select">
  488.                 <xsl:choose>
  489.                     <xsl:when test="@Div">
  490.                         <xsl:text/>string-length($curString<xsl:value-of select="generate-id(.)"/>) / <xsl:value-of select="@Div"/><xsl:text/>
  491.                     </xsl:when>
  492.                     <xsl:when test="@Sub">
  493.                         <xsl:text/>string-length($curString<xsl:value-of select="generate-id(.)"/>) - <xsl:value-of select="@Sub"/><xsl:text/>
  494.                     </xsl:when>
  495.                     <xsl:otherwise>
  496.                         <xsl:text/>string-length($curString<xsl:value-of select="generate-id(.)"/>)<xsl:text/>
  497.                     </xsl:otherwise>
  498.                 </xsl:choose>
  499.             </xsl:attribute>
  500.         </xz:variable>
  501.     </xsl:template>
  502.  
  503.     <xsl:template match="Length" mode="genTemplates">
  504.         <xsl:param name="currentView"/>        
  505.         <xsl:param name="fieldData"/>
  506.         <xsl:param name="renderPattern"/>
  507.         <xsl:param name="Field"/>
  508.         <xsl:param name="ThisField"/>
  509.         
  510.         <xsl:choose>
  511.             <xsl:when test="GetVar">
  512.                 <xsl:text/>string-length(ddwrt:GetVar('<xsl:value-of select="GetVar/@Name"/>'))<xsl:text/>
  513.             </xsl:when>
  514.             <xsl:otherwise>
  515.                 <xsl:text/>{$Length<xsl:value-of select="generate-id(.)"/>}<xsl:text/>
  516.             </xsl:otherwise>
  517.         </xsl:choose>
  518.  
  519.     </xsl:template>
  520.  
  521.  
  522.     <xsl:template match="CrossProjectLink" mode="genTemplates">
  523.         <xsl:param name="currentView"/>        
  524.         <xsl:param name="fieldData"/>
  525.         <xsl:param name="renderPattern"/>
  526.         <xsl:param name="Field"/>
  527.         <xsl:param name="ThisField"/>
  528.         
  529.         <xz:choose>
  530.             <xz:when>
  531.                 <xsl:attribute name="test">not(@WorkspaceLink='1' or @WorkspaceLink='-1')</xsl:attribute>
  532.                 <IMG border="0" width="16" height="16" SRC="{{$ImagesPath}}blank.gif"/>
  533.             </xz:when>
  534.             <xz:otherwise>
  535.                 <xz:variable>
  536.                     <xsl:attribute name="name">meetingName</xsl:attribute>
  537.                     <xsl:attribute name="select">substring-before(@Workspace, ', ')</xsl:attribute> 
  538.                 </xz:variable>
  539.                 <A HREF="{{$meetingName}}" target="_self"><IMG border="0" SRC="{{$ImagesPath}}{$fieldData/@DisplayImage}"/></A>
  540.             </xz:otherwise>
  541.         </xz:choose>
  542.     </xsl:template>
  543.  
  544.     <xsl:template match="XML" mode="genTemplates">
  545.         <xsl:param name="currentView"/>        
  546.         <xsl:param name="fieldData"/>
  547.         <xsl:param name="renderPattern"/>
  548.         <xsl:param name="Field"/>
  549.         <xsl:param name="ThisField"/>
  550.         
  551.         <xsl:apply-templates mode="genTemplates" select="*">
  552.             <xsl:with-param name="currentView" select="$currentView"/>
  553.             <xsl:with-param name="fieldData" select="$fieldData"/>
  554.             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  555.             <xsl:with-param name="Field" select="$Field"/>
  556.             <xsl:with-param name="ThisField" select="$ThisField"/>
  557.         </xsl:apply-templates>
  558.     </xsl:template>
  559.  
  560.     <xsl:template match="LookupColumn" mode="genParams">
  561.         <xsl:param name="currentList"/>
  562.         <xsl:param name="viewNode"/>
  563.     
  564.         <!-- if the lookupcolumn tag is inside the form, and inside a scriptquote tag, we'll add the variable-->
  565.         <xsl:if test="$isAViewAndNotAForm = '0' and ancestor::ScriptQuote">
  566.             <xz:variable>
  567.                 <xsl:attribute name="name"><xsl:value-of select="name(.)"/><xsl:value-of select="generate-id(.)"/></xsl:attribute>
  568.                 <xsl:attribute name="select">/dsQueryResponse/<xsl:value-of select="$resultRoot"/>/<xsl:value-of select="$resultRow"/>[@ID = $ID]/@<xsl:value-of select="@Name"/></xsl:attribute>
  569.             </xz:variable>            
  570.         </xsl:if>
  571.     </xsl:template>
  572.  
  573.     <xsl:template match="Column" mode="genParams">
  574.         <!-- only one -->        
  575.         <xsl:param name="currentList"/>
  576.         <xsl:param name="viewNode"/>
  577.         
  578.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  579.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  580.                 
  581.         <!--make a variable when the preceding node of this current column ends with a " -->        
  582.         <xsl:if test="not(name($viewNode) = 'View')">
  583.         <xsl:choose>
  584.         <xsl:when test="generate-id(current()) = generate-id(($currentList//*[name(current())=name(.) and @HTMLEncode = 'TRUE' and name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = '"'])[1])">
  585.             <xz:variable><xsl:attribute name="name"><xsl:value-of select="name($viewNode)"/></xsl:attribute>
  586.                 <xsl:attribute name="select">@<xsl:value-of select="$viewNode/@Name"/></xsl:attribute>
  587.             </xz:variable>
  588.         </xsl:when>
  589.         <!-- make a variable when the preceding node ends with '='-->
  590.         <xsl:when test="generate-id(current()) = generate-id(($currentList//*[name(current())=name(.) and name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = '='])[1])">
  591.             <xz:variable><xsl:attribute name="name"><xsl:value-of select="generate-id($viewNode)"/></xsl:attribute>
  592.                 <xsl:attribute name="select">@<xsl:value-of select="$viewNode/@Name"/></xsl:attribute>
  593.             </xz:variable>
  594.         </xsl:when>
  595.         </xsl:choose>
  596.         </xsl:if>
  597.     </xsl:template>
  598.     
  599.     <xsl:template name="genParamTag">
  600.         <xsl:param name="currentness2"/>
  601.         <xsl:param name="nodeness"/>
  602.         <xsl:param name="viewNode" />
  603.         <!-- we don't do param when there is attributes to the node (it's probably a run time stuff)-->
  604.         <!-- when viewNode is different from currentness2, it's a field node, we need to make sure 
  605.               no duplication-->
  606.         <xsl:if test="generate-id($nodeness) = generate-id(($currentness2//*[name($nodeness)=name(.) and not (@*)])[1]) and not(not ($viewNode = $currentness2) and $viewNode//*[name(.)=name($nodeness) and not(@*)])">
  607.             <xz:param><xsl:attribute name="name"><xsl:value-of select="name($nodeness)"/></xsl:attribute>
  608.             </xz:param>
  609.         </xsl:if>
  610.     </xsl:template>
  611.  
  612.     <xsl:template name="genRuntimeParamTag">
  613.         <xsl:param name="currentness2"/>
  614.         <xsl:param name="nodeness"/>
  615.         <xsl:param name="viewNode" />
  616.         <!-- when viewNode is different from currentness2, it's a field node, we need to make sure 
  617.               no duplication-->
  618.         <xsl:if test="generate-id($nodeness) = generate-id(($currentness2//*[name($nodeness)=name(.) and not (@*)])[1]) and not(not ($viewNode = $currentness2) and $viewNode//*[name(.)=name($nodeness) and not(@*)])">
  619.             <xz:param>
  620.                 <xsl:attribute name="name"><xsl:value-of select="name($nodeness)"/></xsl:attribute>
  621.                    <xsl:attribute name="select">ddwrt:<xsl:value-of select="name($nodeness)" disable-output-escaping="yes"/>()</xsl:attribute>
  622.             </xz:param>
  623.         </xsl:if>
  624.     </xsl:template>
  625.  
  626.     <xsl:template name="genParamRt">
  627.         <xsl:param name="currentness2"/>
  628.         <xsl:param name="nodeness"/>
  629.         <xsl:param name="viewNode" />
  630.         <!-- we don't do param when there is attributes to the node (it's probably a run time stuff)-->
  631.         <!-- when viewNode is different from currentness2, it's a field node, we need to make sure 
  632.               no duplication-->
  633.         <xsl:if test="generate-id($nodeness) = generate-id(($currentness2//*[name($nodeness)=name(.) and not (@*)])[1])">
  634.             <xz:variable><xsl:attribute name="name"><xsl:value-of select="name($nodeness)" disable-output-escaping="yes"/>_<xsl:value-of select="name($viewNode)"/></xsl:attribute>
  635.                    <xsl:attribute name="select">ddwrt:<xsl:value-of select="name($nodeness)" disable-output-escaping="yes"/>()</xsl:attribute>
  636.             </xz:variable>
  637.         </xsl:if>
  638.     </xsl:template>
  639.  
  640. <!--    
  641. current thinking has GetVar being a runtime function
  642. only getvars that needs to be parameterized are done.
  643. -->        
  644.  
  645.     <xsl:template mode="genParams" match="ListUrlDir">
  646.         <xsl:param name="currentList"/>
  647.         <xsl:param name="viewNode"/>
  648.             <xsl:choose>
  649.                 <xsl:when test="@WebRel">
  650.                     <xsl:call-template name="genParamTagEx">
  651.                     <xsl:with-param name="currentness2" select="$currentList"/>
  652.                     <xsl:with-param name="nodeness" select="."/>
  653.                     <xsl:with-param name="viewNode" select="$viewNode"/>
  654.                     <xsl:with-param name="attr">WebRel</xsl:with-param>
  655.                     <xsl:with-param name="attr-value" select="@WebRel"></xsl:with-param>
  656.                     </xsl:call-template>
  657.                 </xsl:when>
  658.                 <xsl:otherwise>
  659.                 </xsl:otherwise>
  660.             </xsl:choose>
  661.     </xsl:template>
  662.  
  663.     <xsl:template mode="genParams" match="URL">
  664.         <xsl:param name="currentList"/>
  665.         <xsl:param name="viewNode" />
  666.             <xsl:choose>
  667.                 <xsl:when test="@Cmd and not(@Cmd='Display')">
  668.                     <xsl:call-template name="genParamTagEx">
  669.                         <xsl:with-param name="currentness2" select="$currentList"/>
  670.                         <xsl:with-param name="nodeness" select="."/>
  671.                         <xsl:with-param name="viewNode" select="$viewNode"/>
  672.                         <xsl:with-param name="attr">Cmd</xsl:with-param>
  673.                         <xsl:with-param name="attr-value" select="@Cmd"></xsl:with-param>
  674.                     </xsl:call-template>
  675.                 </xsl:when>
  676.                 <xsl:otherwise>
  677.                 </xsl:otherwise>
  678.             </xsl:choose>            
  679.     </xsl:template>
  680.  
  681.     <xsl:template mode="genParams" match="LocaleInfo">
  682.         <xsl:param name="currentList"/>
  683.         <xsl:param name="viewNode"/>
  684.          <xsl:call-template name="genParamTagEx">
  685.             <xsl:with-param name="currentness2" select="$currentList"/>
  686.             <xsl:with-param name="nodeness" select="."/>
  687.             <xsl:with-param name="viewNode" select="$viewNode"/>            
  688.             <xsl:with-param name="attr">LCTYPE</xsl:with-param>
  689.             <xsl:with-param name="attr-value" select="@LCTYPE"></xsl:with-param>
  690.         </xsl:call-template>
  691.     </xsl:template>
  692.  
  693.     <xsl:template name="genParamTagRt">
  694.         <xsl:param name="currentness2"/>
  695.         <xsl:param name="nodeness"/>
  696.         <xsl:param name="viewNode"/>
  697.         <xsl:param name="attr"/>
  698.         <xsl:param name="attr-value"/>
  699.         <!-- when viewNode is different from currentness2, it's a field node, we need to make sure 
  700.               no duplication-->        
  701.         <xsl:if test="generate-id($nodeness) = generate-id(($currentness2//*[name($nodeness)=name(.) and @*[$attr] = $attr-value])[1]) and not(not ($viewNode = $currentness2) and $viewNode//*[name(.)=name($nodeness) and @*[$attr] = $attr-value])">
  702.             <xz:param>
  703.                 <xsl:attribute name="name"><xsl:value-of select="name($nodeness)" disable-output-escaping="yes"/>_<xsl:value-of select="$attr-value"/></xsl:attribute>
  704.                    <xsl:attribute name="select">ddwrt:<xsl:value-of select="name($nodeness)" disable-output-escaping="yes"/>('<xsl:value-of select="$attr-value"/>')</xsl:attribute>
  705.             </xz:param>
  706.         </xsl:if>
  707.     </xsl:template>
  708.         
  709.     <xsl:template name="genParamTagEx">
  710.         <xsl:param name="currentness2"/>
  711.         <xsl:param name="nodeness"/>
  712.         <xsl:param name="viewNode"/>
  713.         <xsl:param name="attr"/>
  714.         <xsl:param name="attr-value"/>
  715.         <!-- when viewNode is different from currentness2, it's a field node, we need to make sure 
  716.               no duplication-->        
  717.         <xsl:if test="generate-id($nodeness) = generate-id(($currentness2//*[name($nodeness)=name(.) and @*[name(.) = $attr] = $attr-value])[1]) and not(not ($viewNode = $currentness2) and $viewNode//*[name(.)=name($nodeness) and @*[name(.) = $attr] = $attr-value])">
  718.             <xz:param>
  719.                 <xsl:attribute name="name">
  720.                     <xsl:value-of select="name($nodeness)"/>_<xsl:value-of select="$attr-value"/>
  721.                 </xsl:attribute>
  722.             </xz:param>
  723.         </xsl:if>
  724.     </xsl:template>
  725.     
  726.     <!-- this is the stuff for generating the root template, which is 
  727.         basically just a series of call-template and apply-templates -->
  728.     <xsl:template match="*" mode="genRootTemplate">
  729.         <xsl:param name="currentView"/>
  730.  
  731.         <xz:template match="/">
  732.             <xz:call-template name="dvt_1" />
  733.         </xz:template>
  734.         
  735.         <xz:template name="dvt_1">
  736.             <xz:variable> 
  737.                 <xsl:attribute name="name"><xsl:choose><xsl:when test="$codeReduced='1'">dvt_StyleName</xsl:when><xsl:otherwise>StyleName</xsl:otherwise></xsl:choose></xsl:attribute>Table</xz:variable>
  738.             <xz:variable name="Rows">
  739.                 <xsl:attribute name="select">/dsQueryResponse/<xsl:value-of select="$resultRoot"/>/<xsl:value-of select="$resultRow"/></xsl:attribute>
  740.             </xz:variable>
  741.             <xz:variable>
  742.                 <xsl:attribute name="name"><xsl:choose><xsl:when test="$codeReduced='1'">dvt_RowCount</xsl:when><xsl:otherwise>RowCount</xsl:otherwise></xsl:choose></xsl:attribute>
  743.                 <xsl:attribute name="select"><xsl:text>count($Rows)</xsl:text></xsl:attribute>
  744.             </xz:variable>
  745.             <xsl:variable name="RowLimit" select="RowLimit"/>
  746.             <xz:variable name="RowLimit">
  747.                 <xsl:choose>
  748.                     <xsl:when test="$RowLimit"><xsl:value-of select="number($RowLimit)"/></xsl:when>
  749.                     <xsl:otherwise>100</xsl:otherwise>
  750.                 </xsl:choose>
  751.             </xz:variable>
  752.             <xsl:if test="RowLimit[@Paged='TRUE']">
  753.                 <xz:variable>
  754.                     <xsl:attribute name="name">FirstRow</xsl:attribute>
  755.                     <xsl:attribute name="select">$dvt_firstrow</xsl:attribute>    
  756.                 </xz:variable>
  757.  
  758.                 <xsl:choose>
  759.                     <xsl:when test="$codeReduced='1'">
  760.                         <xz:variable>
  761.                             <xsl:attribute name="name">LastRow</xsl:attribute>
  762.                                       <xsl:attribute name="select">$FirstRow + $dvt_RowCount - 1</xsl:attribute>
  763.                         </xz:variable>
  764.                     </xsl:when>
  765.                     <xsl:otherwise>
  766.                         <xz:variable>
  767.                             <xsl:attribute name="name">LastRow</xsl:attribute>
  768.                             <xz:choose>
  769.                                 <xz:when test="($FirstRow + $RowLimit - 1) > $RowCount"><xz:value-of><xsl:attribute name="select">$RowCount</xsl:attribute></xz:value-of></xz:when>
  770.                                 <xz:otherwise><xz:value-of><xsl:attribute name="select">$FirstRow + $RowLimit - 1</xsl:attribute></xz:value-of></xz:otherwise>
  771.                             </xz:choose>
  772.                         </xz:variable>
  773.                     </xsl:otherwise>
  774.                 </xsl:choose>
  775.             </xsl:if>
  776.  
  777.             <xz:variable>
  778.                 <xsl:attribute name="name"><xsl:choose><xsl:when test="$codeReduced='1'">dvt_IsEmpty</xsl:when><xsl:otherwise>IsEmpty</xsl:otherwise></xsl:choose></xsl:attribute>
  779.                 <xsl:attribute name="select">
  780.                     <xsl:choose>
  781.                         <xsl:when test="$codeReduced='1'"><xsl:text>$dvt_RowCount = 0</xsl:text></xsl:when>
  782.                         <xsl:otherwise><xsl:text>$RowCount = 0</xsl:text></xsl:otherwise>
  783.                     </xsl:choose>
  784.                 </xsl:attribute>
  785.             </xz:variable>
  786.  
  787.             <!-- view node attribute FreeForm=TRUE means set the FreeForm var-->
  788.             <xsl:if test="$currentView/@FreeForm='TRUE'">
  789.                 <xz:value-of>
  790.                     <xsl:attribute name="select">
  791.                         <xsl:text/>ddwrt:SetVar('FreeForm', 'TRUE')<xsl:text/>
  792.                     </xsl:attribute>
  793.                 </xz:value-of>
  794.             </xsl:if>
  795.  
  796.             <!-- the big html tag to enclose all inside tags, also exluce all the redundant
  797.                    tags -->
  798.             
  799.             
  800.             <!--no matter where toolbar is in the xml, it'll be shown the earliest. 
  801.                   so we do it first, then do the rest (excluding the toolbar)-->
  802.             <xsl:if test="Toolbar[not(@Position='After')] and not($codeReduced = '1')">
  803.                 <xz:call-template name="dvt_1.toolbar">
  804.                     <xz:with-param name="Rows">
  805.                         <xsl:attribute name="select">$Rows</xsl:attribute>
  806.                     </xz:with-param>
  807.                 </xz:call-template>
  808.             </xsl:if>
  809.             
  810.             <!--<xsl:apply-templates select="Toolbar[not(@Position='After')]" mode="doGenRootTemplate">
  811.                 <xsl:with-param name="currentView" select="$currentView"/>
  812.             </xsl:apply-templates>-->
  813.  
  814.             <!-- if we have viewheaderbidi, use it in place of viewheader. -->
  815.             <xsl:variable name="hasBidi" select="./ViewBidiHeader"/>
  816.             <xsl:variable name="Direction" select="/List/@Direction"/>
  817.         
  818.             <xz:choose>
  819.                 <xz:when>
  820.                     <xsl:attribute name="test"><xsl:text>$</xsl:text><xsl:choose><xsl:when test="$codeReduced='1'">dvt_IsEmpty</xsl:when><xsl:otherwise>IsEmpty</xsl:otherwise></xsl:choose></xsl:attribute>
  821.                     <xsl:apply-templates mode="genTemplates" select="*[name(.) = 'ViewEmpty']/*">
  822.                         <xsl:with-param name="currentView" select="$currentView"/>
  823.                         <xsl:with-param name="fieldData" select="*"/>
  824.                         <xsl:with-param name="renderPattern" select="'HeaderPattern'"/>
  825.                         <xsl:with-param name="Field" select="."/>
  826.                     </xsl:apply-templates>
  827.                     
  828.                     <xsl:if test="Toolbar[@Position='After']">
  829.                         <xz:call-template name="dvt_1.toolbar">
  830.                             <xz:with-param name="Rows">
  831.                                 <xsl:attribute name="select">$Rows</xsl:attribute>
  832.                             </xz:with-param>
  833.                         </xz:call-template>
  834.                     </xsl:if>
  835.  
  836.                 </xz:when>
  837.                 <xz:otherwise>        
  838.                     <xsl:choose>
  839.                         <xsl:when test="$hasBidi and not ($Direction = '' ) and not ($Direction='0')">    
  840.                             <xsl:apply-templates select="ViewBidiHeader" mode="doGenRootTemplate">
  841.                                 <xsl:with-param name="currentView" select="$currentView"/>
  842.                             </xsl:apply-templates>
  843.                         </xsl:when>
  844.                         <xsl:otherwise>
  845.                         <xsl:apply-templates select="ViewHeader" mode="doGenRootTemplate">
  846.                             <xsl:with-param name="currentView" select="$currentView"/>
  847.                         </xsl:apply-templates>                            
  848.                         </xsl:otherwise>
  849.                     </xsl:choose>    
  850.                     
  851.                     <xsl:apply-templates select="ViewBody" mode="doGenRootTemplate">
  852.                         <xsl:with-param name="currentView" select="$currentView"/>
  853.                     </xsl:apply-templates>
  854.  
  855.                     <xsl:apply-templates select="ViewFooter" mode="doGenRootTemplate">
  856.                         <xsl:with-param name="currentView" select="$currentView"/>
  857.                     </xsl:apply-templates>
  858.  
  859.                     <xsl:if test="Toolbar[@Position='After']">
  860.                         <xz:call-template name="dvt_1.toolbar">
  861.                             <xz:with-param name="Rows">
  862.                                 <xsl:attribute name="select">$Rows</xsl:attribute>
  863.                             </xz:with-param>
  864.                         </xz:call-template>
  865.                     </xsl:if>
  866.  
  867.                     <!--<xsl:apply-templates select="Toolbar[@Position='After']" mode="doGenRootTemplate">
  868.                         <xsl:with-param name="currentView" select="$currentView"/>
  869.                     </xsl:apply-templates>-->
  870.                 </xz:otherwise>    
  871.             </xz:choose>
  872.     
  873.             
  874.         </xz:template>
  875.     </xsl:template>
  876.     
  877.     <xsl:template match="*" mode="doGenRootTemplate">
  878.         <xsl:param name="currentView"/>
  879.         <xsl:choose>
  880.             <xsl:when test="name() = 'ListFormBody'">
  881.                 <xz:apply-templates select="/dsQueryResponse/Rows/Row" mode="row">
  882.                 </xz:apply-templates>
  883.             </xsl:when>
  884.             <xsl:when test="name() = 'PagedRecurrenceRowset'">
  885.             </xsl:when>
  886.             <xsl:otherwise>
  887.                 <xsl:apply-templates select="*" mode="genTemplates">
  888.                     <xsl:with-param name="currentView" select="$currentView"/>
  889.                     <xsl:with-param name="fieldData" select="*"/>
  890.                     <xsl:with-param name="renderPattern" select="'HeaderPattern'"/>
  891.                     <xsl:with-param name="Field" select="."/>                                
  892.                 </xsl:apply-templates>
  893.             </xsl:otherwise>
  894.         </xsl:choose>        
  895.     </xsl:template>
  896.         
  897.     <xsl:template match="ListFormBody" mode="doGenRootTemplate">
  898.         <xsl:param name="currentView"/>
  899.         <xsl:choose>  <!-- for display form, only show the items that's selected by ID -->
  900.             <xsl:when test="$formType = 'DisplayForm' or $formType = 'EditForm'">
  901.                 <xz:apply-templates>
  902.                     <xsl:attribute name="select">/dsQueryResponse/<xsl:value-of select="$resultRoot"/>/<xsl:value-of select="$resultRow"/></xsl:attribute>
  903.                     <xsl:attribute name="mode">row</xsl:attribute>
  904.                 </xz:apply-templates>
  905.             </xsl:when>
  906.             <!--new form doesn't really take z:row as input, instead it'll always output one set. -->
  907.             <xsl:when test="($formType = 'NewForm') and ($generalDisplayPattern = 'EditPattern')">
  908.                 <xz:call-template name="ListFormBody"/>
  909.             </xsl:when>
  910.             <xsl:otherwise>
  911.                 <xz:apply-templates select=""/>
  912.             </xsl:otherwise>
  913.         </xsl:choose>
  914.     </xsl:template>
  915.     
  916.     <!-- when body is empty, show the text in viewempty node-->    
  917.     <xsl:template match="ViewBody" mode="doGenRootTemplate">
  918.         <xsl:param name="currentView"/>
  919.                 
  920.         <xz:call-template name="dvt_1.body">
  921.             <xsl:if test="$codeReduced='1'">
  922.                 <xz:with-param name="ParentPath"/>
  923.             </xsl:if>    
  924.             <xz:with-param name="Rows" select="$Rows"/>
  925.             <xz:with-param name="FirstRow" select="1"/>
  926.             <xz:with-param name="LastRow" select="5"/>
  927.         </xz:call-template>
  928.     </xsl:template>
  929.  
  930.     <!-- viewfields and query do nothing
  931.           they are useful for the fields representation 
  932.           viewEmpty is used when viewbody is empty.-->
  933.     <xsl:template match="ViewFields|Query|ViewEmpty" mode="doGenRootTemplate"/>
  934.  
  935.     <!-- this is the stuff for generating the various second-level templates
  936.         which correspond to the top level nodes beneath form and view -->
  937.     <xsl:template mode="genTemplates" match="ListFormOpening|ListFormButtons|ListFormBody|ListFormClosing">
  938.         <xsl:param name="currentView"/>
  939.         <xsl:param name="fieldData"/>
  940.         <xsl:param name="renderPattern"/>        
  941.         <xsl:param name="Field"/>
  942.  
  943.         <xz:template name="{name()}">
  944.         <!--z:row is not for the NewPattern in form -->
  945.         <xsl:if test="name() = 'ListFormBody' and not($renderPattern = 'NewPattern' and $generalDisplayPattern = 'EditPattern')">
  946.             <xsl:attribute name="match">*</xsl:attribute>
  947.             <xsl:attribute name="mode">row</xsl:attribute>
  948.         </xsl:if>
  949.         
  950.         <xsl:apply-templates mode="genTemplates" select="*">
  951.             <xsl:with-param name="currentView" select="$currentView"/>
  952.             <xsl:with-param name="fieldData" select="$fieldData"/>
  953.             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  954.             <xsl:with-param name="Field" select="."/>                        
  955.         </xsl:apply-templates>
  956.         </xz:template>
  957.     </xsl:template>
  958.  
  959.     <xsl:template mode="doGenRootTemplate" match="PagedRowset">
  960.         <xsl:param name="currentView"/>
  961.         <xsl:param name="fieldData"/>
  962.         <xsl:param name="renderPattern"/>        
  963.         <xsl:param name="Field"/>
  964.  
  965.         <xsl:if test="not(preceding-sibling::*[name(.) = name(current())])">
  966.         <xsl:variable name="RowLimit" select="number(following-sibling::*[name(.) = 'RowLimit']|preceding-sibling::*[name(.) = 'RowLimit'])"/>
  967.         <xz:variable>
  968.             <xsl:attribute name="name">DataSize</xsl:attribute>
  969.             <xsl:attribute name="select">count(/dsQueryResponse/<xsl:value-of select="$resultRoot"/>/<xsl:value-of select="$resultRow"/>)</xsl:attribute>
  970.         </xz:variable>
  971.         <xz:if>
  972.         <xsl:attribute name="test"><xsl:text><![CDATA[ $DataSize >= ]]></xsl:text><xsl:value-of select="$RowLimit"/><xsl:text disable-output-escaping="yes"><![CDATA[ +$FirstRow]]></xsl:text></xsl:attribute>
  973.                 <xsl:apply-templates select="*" mode="genTemplates">
  974.                     <xsl:with-param name="currentView" select="$currentView"/>
  975.                     <xsl:with-param name="fieldData" select="*"/>
  976.                     <xsl:with-param name="renderPattern" select="'HeaderPattern'"/>
  977.                     <xsl:with-param name="Field" select="."/>                                
  978.                 </xsl:apply-templates>
  979.         </xz:if>
  980.         </xsl:if>
  981.     </xsl:template>
  982.  
  983.     <xsl:template mode="doGenRootTemplate" match="RowLimitExceeded">
  984.         <xsl:param name="currentView"/>
  985.         <xsl:param name="fieldData"/>
  986.         <xsl:param name="renderPattern"/>        
  987.         <xsl:param name="Field"/>
  988.  
  989.         <xsl:if test="not(preceding-sibling::*[name(.) = name(current())])">
  990.         <xsl:variable name="RowLimit" select="number(following-sibling::*[name(.) = 'RowLimit']|preceding-sibling::*[name(.) = 'RowLimit'])"/>
  991.         <xz:variable>
  992.             <xsl:attribute name="name">DataSize</xsl:attribute>
  993.             <xsl:attribute name="select">count(/dsQueryResponse/<xsl:value-of select="$resultRoot"/>/<xsl:value-of select="$resultRow"/>)</xsl:attribute>        
  994.         </xz:variable>
  995.         <xz:if>
  996.         <xsl:attribute name="test"><xsl:text disable-output-escaping="yes"><![CDATA[ $DataSize > ]]></xsl:text><xsl:value-of select="$RowLimit"/></xsl:attribute>
  997.                 <xsl:apply-templates select="*" mode="genTemplates">
  998.                     <xsl:with-param name="currentView" select="$currentView"/>
  999.                     <xsl:with-param name="fieldData" select="*"/>
  1000.                     <xsl:with-param name="renderPattern" select="'HeaderPattern'"/>
  1001.                     <xsl:with-param name="Field" select="."/>                                
  1002.                 </xsl:apply-templates>
  1003.         </xz:if>
  1004.         </xsl:if>
  1005.     </xsl:template>
  1006.  
  1007.     <xsl:template mode="genTemplates" match="ViewBody">
  1008.         <xsl:param name="currentView"/>
  1009.         <xsl:param name="fieldData"/>
  1010.         <xsl:param name="renderPattern"/>        
  1011.         <xsl:param name="Field"/>
  1012.         
  1013.         <!-- for V3 dfwp, we'll have a new paradigm that uses new templates-->
  1014.         <xsl:choose>
  1015.             <xsl:when test="$codeReduced='1'">
  1016.                 <xz:template name="dvt_1.body">
  1017.                     <xz:param name="ParentPath"/>
  1018.                     <xz:param name="Rows"/>
  1019.                     <xz:param name="FirstRow"/>
  1020.                     <xz:param name="LastRow"/>
  1021.                     
  1022.                     <xz:for-each select="$Rows">
  1023.                         <xz:variable>
  1024.                             <xsl:attribute name="name">dvt_KeepItemsTogether</xsl:attribute>
  1025.                             <xsl:attribute name="select">false()</xsl:attribute>
  1026.                         </xz:variable>
  1027.                         <xz:variable>
  1028.                             <xsl:attribute name="name">dvt_HideGroupDetail</xsl:attribute>
  1029.                             <xsl:attribute name="select">false()</xsl:attribute>
  1030.                         </xz:variable>
  1031.  
  1032.                         <xz:if>
  1033.                             <xsl:attribute name="test"><xsl:text><![CDATA[ (position() >=$FirstRow and position() <= $LastRow) or $]]></xsl:text><xsl:choose><xsl:when test="$codeReduced='1'">dvt_KeepItemsTogether</xsl:when><xsl:otherwise>KeepItemsTogether</xsl:otherwise></xsl:choose></xsl:attribute>
  1034.                             <xz:if>
  1035.                                 <xsl:attribute name="test"><xsl:choose><xsl:when test="$codeReduced='1'">not($dvt_HideGroupDetail)</xsl:when><xsl:otherwise>not($HideGroupDetail)</xsl:otherwise></xsl:choose></xsl:attribute>
  1036.                                 <xsl:attribute name="ddwrt:cf_ignore">1</xsl:attribute>
  1037.                 
  1038.                                 <xz:variable name="SrcPos"><xz:number/></xz:variable>
  1039.                                 <xz:call-template name="dvt_1.rowview">
  1040.                                     <xz:with-param name="ParentPath" select="$ParentPath"/>
  1041.                                     <xz:with-param name="SrcPos" select="$SrcPos"/>
  1042.                                 </xz:call-template>
  1043.                             </xz:if>
  1044.                         </xz:if>
  1045.                     </xz:for-each>
  1046.                 </xz:template>    
  1047.                 
  1048.                 <xz:template name="dvt_1.rowview">
  1049.                     <xz:param name="ParentPath"/>
  1050.                     <xz:param name="SrcPos"/>
  1051.  
  1052.                         <xsl:apply-templates select=".//Switch" mode="genVariablesInField">
  1053.                             <xsl:with-param name="currentView" select="$currentView"/>
  1054.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  1055.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1056.                             <xsl:with-param name="Field" select="."/>                        
  1057.                         </xsl:apply-templates>        
  1058.                                             
  1059.                         <xsl:apply-templates mode="genTemplates" select="*">
  1060.                             <xsl:with-param name="currentView" select="$currentView"/>
  1061.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  1062.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1063.                             <xsl:with-param name="Field" select="."/>                        
  1064.                         </xsl:apply-templates>
  1065.                 </xz:template>
  1066.             
  1067.             </xsl:when>
  1068.             <xsl:otherwise>
  1069.                 <xz:template name="dvt_1.body">
  1070.                     <xz:param name="Rows"/>
  1071.                     <xz:param name="FirstRow"/>
  1072.                     <xz:param name="LastRow"/>
  1073.                     <xz:for-each select="$Rows">
  1074.                     
  1075.                 <xz:variable>
  1076.                     <xsl:attribute name="name"><xsl:choose><xsl:when test="$codeReduced='1'">dvt_KeepItemsTogether</xsl:when><xsl:otherwise>KeepItemsTogether</xsl:otherwise></xsl:choose></xsl:attribute>
  1077.                     <xsl:attribute name="select">false()</xsl:attribute>
  1078.                 </xz:variable>
  1079.                 <xz:variable>
  1080.                     <xsl:attribute name="name"><xsl:choose><xsl:when test="$codeReduced='1'">dvt_HideGroupDetail</xsl:when><xsl:otherwise>HideGroupDetail</xsl:otherwise></xsl:choose></xsl:attribute>
  1081.                     <xsl:attribute name="select">false()</xsl:attribute>
  1082.                 </xz:variable>
  1083.                 <xz:variable>
  1084.                     <xsl:attribute name="name"><xsl:choose><xsl:when test="$codeReduced='1'">dvt_GroupStyle</xsl:when><xsl:otherwise>GroupStyle</xsl:otherwise></xsl:choose></xsl:attribute>
  1085.                     <xsl:attribute name="select">'auto'</xsl:attribute>
  1086.                 </xz:variable>
  1087.  
  1088.                 <xz:if>
  1089.                     <xsl:attribute name="test"><xsl:text><![CDATA[ (position() >=$FirstRow and position() <= $LastRow) or $]]></xsl:text><xsl:choose><xsl:when test="$codeReduced='1'">dvt_KeepItemsTogether</xsl:when><xsl:otherwise>KeepItemsTogether</xsl:otherwise></xsl:choose></xsl:attribute>
  1090.                     <xz:if>
  1091.                         <xsl:attribute name="test"><xsl:choose><xsl:when test="$codeReduced='1'">not($dvt_HideGroupDetail)</xsl:when><xsl:otherwise>not($HideGroupDetail)</xsl:otherwise></xsl:choose></xsl:attribute>
  1092.                         <xsl:attribute name="ddwrt:cf_ignore">1</xsl:attribute>
  1093.  
  1094.                         <xsl:apply-templates select=".//Switch" mode="genVariablesInField">
  1095.                             <xsl:with-param name="currentView" select="$currentView"/>
  1096.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  1097.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1098.                             <xsl:with-param name="Field" select="."/>                        
  1099.                         </xsl:apply-templates>        
  1100.                         
  1101.                         <xsl:apply-templates mode="genTemplates" select="*">
  1102.                             <xsl:with-param name="currentView" select="$currentView"/>
  1103.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  1104.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1105.                             <xsl:with-param name="Field" select="."/>                        
  1106.                         </xsl:apply-templates>
  1107.                     </xz:if>
  1108.                 </xz:if>
  1109.                 </xz:for-each>    
  1110.                 </xz:template>
  1111.             </xsl:otherwise>
  1112.         </xsl:choose>
  1113.     </xsl:template>
  1114.  
  1115.     <xsl:template mode="genTemplates" match="GroupByHeader">
  1116.         <xsl:param name="currentView"/>
  1117.         <xsl:param name="fieldData"/>
  1118.         <xsl:param name="renderPattern"/>        
  1119.         <xsl:param name="Field"/>
  1120.         
  1121.         <xz:template name="dvt_1.groupheader">
  1122.             <xz:param name="Rows" />
  1123.         
  1124.             <xsl:apply-templates mode="genTemplates" select="*">
  1125.                 <xsl:with-param name="currentView" select="$currentView"/>
  1126.                 <xsl:with-param name="fieldData" select="$fieldData"/>
  1127.                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1128.                 <xsl:with-param name="Field" select="$Field"/>                        
  1129.             </xsl:apply-templates>
  1130.         </xz:template>
  1131.     </xsl:template>
  1132.  
  1133.     <xsl:template mode="genTemplates" match="GroupByFooter">
  1134.         <xsl:param name="currentView"/>
  1135.         <xsl:param name="fieldData"/>
  1136.         <xsl:param name="renderPattern"/>        
  1137.         <xsl:param name="Field"/>
  1138.         
  1139.         <xz:template name="dvt_1.groupfooter">
  1140.             <xz:param name="Rows" />
  1141.         
  1142.             <xsl:apply-templates mode="genTemplates" select="*">
  1143.                 <xsl:with-param name="currentView" select="$currentView"/>
  1144.                 <xsl:with-param name="fieldData" select="$fieldData"/>
  1145.                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1146.                 <xsl:with-param name="Field" select="$Field"/>                        
  1147.             </xsl:apply-templates>
  1148.         </xz:template>
  1149.     </xsl:template>
  1150.     
  1151.     <xsl:template mode="genTemplates" match="Toolbar">
  1152.         <xsl:param name="currentView"/>
  1153.         <xsl:param name="fieldData"/>
  1154.         <xsl:param name="renderPattern"/>        
  1155.         <xsl:param name="Field"/>
  1156.         
  1157.         <xz:template name="dvt_1.toolbar">
  1158.             <xz:param name="Rows" />
  1159.         
  1160.             <xsl:apply-templates mode="genTemplates" select="*">
  1161.                 <xsl:with-param name="currentView" select="$currentView"/>
  1162.                 <xsl:with-param name="fieldData" select="$fieldData"/>
  1163.                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1164.                 <xsl:with-param name="Field" select="$Field"/>                        
  1165.             </xsl:apply-templates>
  1166.             
  1167.             <!-- add in the ddw add hoc filter -->
  1168.             <!-- (leave the statement empty, it will get filled in by FP) -->
  1169.             <!-- FP 11 only -->
  1170.             <xsl:if test="not($codeReduced = '1')">
  1171.                 <xz:if test="$dvt_adhocmode = 'filter'" ddwrt:cf_ignore="1">
  1172.                 </xz:if>
  1173.             </xsl:if>
  1174.                 
  1175.         </xz:template>
  1176.     </xsl:template>
  1177.  
  1178.     <!-- FieldProperty is not documented and so far no text to show -->
  1179.     <xsl:template mode="genTemplates" match="FieldProperty">
  1180.         <xsl:param name="currentView"/>        
  1181.         <xsl:param name="fieldData"/>
  1182.         <xsl:param name="renderPattern"/>
  1183.         <xsl:param name="Field"/>        
  1184.         
  1185.         <!-- if inside expr and single child, we'll output the ''-->
  1186.         <xsl:choose>
  1187.         <xsl:when test="(name(ancestor::*[1])='Expr' or name(ancestor::*[1])='Expr1' or name(ancestor::*[1])='Expr2') and not(preceding-sibling::*[1]) and not(following-sibling::*[1])">
  1188.             <xsl:text/>'<xsl:value-of select="/List/MetaData/Fields/Field[@Name=current()/@Name]/@*[name()=current()/@Select]"></xsl:value-of>'<xsl:text/>
  1189.         </xsl:when>        
  1190.         <xsl:otherwise>
  1191.             <xsl:text/><xsl:value-of select="/List/MetaData/Fields/Field[@Name=current()/@Name]/@*[name()=current()/@Select]"></xsl:value-of><xsl:text/>
  1192.         </xsl:otherwise>            
  1193.         </xsl:choose>
  1194.     </xsl:template>
  1195.  
  1196.     <xsl:template mode="genTemplates" match="*">
  1197.         <xsl:param name="currentView"/>        
  1198.         <xsl:param name="fieldData"/>
  1199.         <xsl:param name="renderPattern"/>
  1200.         <xsl:param name="Field"/>
  1201.  
  1202.         <xsl:choose>
  1203.             <xsl:when test="name(ancestor::*[1])='Expr' or name(ancestor::*[1])='Expr1' or name(ancestor::*[1])='Expr2'">''</xsl:when>
  1204.             <xsl:when test="(name(ancestor::*[1])='Expr' or name(ancestor::*[1])='Expr1' or name(ancestor::*[1])='Expr2') and name(.)='ServerProperty' and @Select='HtmlTransform'">''</xsl:when>
  1205.             <xsl:when test="text()"><xsl:value-of select="."/></xsl:when>
  1206.         </xsl:choose>
  1207.     </xsl:template>
  1208.  
  1209.     <xsl:template mode="genTemplates" match="CAMLScript">
  1210.         <xsl:param name="currentView"/>        
  1211.         <xsl:param name="fieldData"/>
  1212.         <xsl:param name="renderPattern"/>
  1213.         <xsl:param name="Field"/>
  1214.         
  1215.         <xsl:apply-templates mode="genTemplates-inscript" select="*">
  1216.             <xsl:with-param name="currentView" select="$currentView"/>
  1217.             <xsl:with-param name="fieldData" select="$fieldData"/>
  1218.             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1219.         </xsl:apply-templates>
  1220.     </xsl:template>    
  1221.  
  1222.     <xsl:template mode="genTemplates" match="TodayISO">
  1223.         <xsl:text/>            
  1224.             <xz:value-of>
  1225.                     <xsl:attribute name="select">ddwrt:TodayISO()</xsl:attribute>
  1226.             </xz:value-of><xsl:text/>
  1227.     </xsl:template>
  1228.  
  1229.     <!-- for MapToIcon nodes, just use the variable we've already defined.-->
  1230.     <xsl:template mode="genTemplates" match="MapToAll">
  1231.         <xsl:param name="currentView"/>        
  1232.         <xsl:param name="fieldData"/>
  1233.         <xsl:param name="renderPattern"/>
  1234.         <xsl:param name="Field"/>
  1235.  
  1236.         <xsl:text/>{ddwrt:MapToAll(<xsl:for-each select="Column">string(@<xsl:value-of select="@Name"/>)<xsl:if test="not (position() = last())">,</xsl:if></xsl:for-each>)}<xsl:text/>
  1237.     </xsl:template>
  1238.  
  1239.  
  1240.     <!-- for MapToIcon nodes, just use the variable we've already defined.-->
  1241.     <xsl:template mode="genTemplates" match="MapToIcon">
  1242.         <xsl:param name="currentView"/>        
  1243.         <xsl:param name="fieldData"/>
  1244.         <xsl:param name="renderPattern"/>
  1245.         <xsl:param name="Field"/>
  1246.  
  1247.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>
  1248.         <xsl:choose>
  1249.             <xsl:when test="name($prevNode)='HTML'">
  1250.                 <xsl:text/>{ddwrt:MapToIcon(<xsl:for-each select="Column">string(@<xsl:value-of select="@Name"/>)<xsl:if test="not (position() = last())">,</xsl:if></xsl:for-each>)}<xsl:text/>
  1251.             </xsl:when>
  1252.             <xsl:otherwise>
  1253.                 <xsl:text/><xz:value-of>
  1254.                     <xsl:attribute name="select">ddwrt:MapToIcon(<xsl:for-each select="Column">string(@<xsl:value-of select="@Name"/>)<xsl:if test="not (position() = last())">,</xsl:if></xsl:for-each>)</xsl:attribute>
  1255.                 </xz:value-of><xsl:text/>
  1256.             </xsl:otherwise>
  1257.         </xsl:choose>
  1258.     </xsl:template>
  1259.     
  1260.     <xsl:template mode="genTemplates" match="MapToControl">
  1261.         <xsl:param name="currentView"/>        
  1262.         <xsl:param name="fieldData"/>
  1263.         <xsl:param name="renderPattern"/>
  1264.         <xsl:param name="Field"/>
  1265.  
  1266.         <xsl:choose>
  1267.             <xsl:when test="ancestor::Expr or ancestor::Expr1 or ancestor::Expr2">
  1268.                 <xsl:text/>ddwrt:MapToControl('', string(<xsl:apply-templates mode="genTemplates-inscript" select="GetFileExtension">
  1269.                     <xsl:with-param name="currentView" select="$currentView"/>
  1270.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  1271.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1272.                     <xsl:with-param name="Field" select="."/>                            
  1273.                 </xsl:apply-templates>))<xsl:text/>
  1274.             </xsl:when>
  1275.             <xsl:when test="ancestor::ScriptQuote">
  1276.                 <xsl:text/>{ddwrt:MapToControl(<xsl:call-template name="ProperEscapedApostrophe" /><xsl:call-template name="ProperEscapedApostrophe" />, string(<xsl:apply-templates mode="genTemplates-inscript" select="GetFileExtension">
  1277.                     <xsl:with-param name="currentView" select="$currentView"/>
  1278.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  1279.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1280.                     <xsl:with-param name="Field" select="."/>
  1281.                 </xsl:apply-templates>))}<xsl:text/>
  1282.             </xsl:when>
  1283.             <xsl:otherwise>
  1284.                 <xsl:text/><xz:value-of>
  1285.                 <xsl:attribute name="select">ddwrt:MapToControl('', string(<xsl:apply-templates mode="genTemplates-inscript" select="GetFileExtension">
  1286.                     <xsl:with-param name="currentView" select="$currentView"/>
  1287.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  1288.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1289.                     <xsl:with-param name="Field" select="."/>                            
  1290.                 </xsl:apply-templates>))</xsl:attribute>
  1291.                 </xz:value-of><xsl:text/>
  1292.             </xsl:otherwise>
  1293.         </xsl:choose>    
  1294.     </xsl:template>
  1295.  
  1296.     <xsl:template mode="genTemplates-inscript" match="MapToIcon">
  1297.         <xsl:param name="currentView"/>        
  1298.         <xsl:param name="fieldData"/>
  1299.         <xsl:param name="renderPattern"/>
  1300.         <xsl:param name="Field"/>
  1301.  
  1302.         <xsl:text/>{ddwrt:MapToIcon(<xsl:for-each select="Column">string(@<xsl:value-of select="@Name"/>)<xsl:if test="not (position() = last())">,</xsl:if></xsl:for-each>)}<xsl:text/>
  1303.     </xsl:template>
  1304.  
  1305.     <xsl:template mode="genTemplates-inscript" match="GetFileExtension">
  1306.         <xsl:param name="currentView"/>        
  1307.         <xsl:param name="fieldData"/>
  1308.         <xsl:param name="renderPattern"/>
  1309.         <xsl:param name="Field"/>
  1310.         
  1311.         <xsl:text/>ddwrt:<xsl:value-of select="name(.)"/>(ddwrt:ListProperty(<xsl:call-template name="ProperEscapedApostrophe" /><xsl:value-of select="ListProperty/@Select"/><xsl:call-template name="ProperEscapedApostrophe" />))<xsl:text/>
  1312.  
  1313.     </xsl:template>
  1314.  
  1315.     <xsl:template mode="genTemplates" match="UrlDirName[LookupColumn/@Name]">
  1316.         <xsl:param name="currentView"/>        
  1317.         <xsl:param name="fieldData"/>
  1318.         <xsl:param name="renderPattern"/>
  1319.         <xsl:param name="Field"/>
  1320.         
  1321.         <xsl:text/>{ddwrt:UrlDirName(string(@<xsl:value-of select="LookupColumn/@Name"/>))}<xsl:text/>
  1322.     </xsl:template>
  1323.  
  1324.     <!-- UrlBaseName is a SharePoint runtime function that takes a string url as input and 
  1325.           output the basename.-->
  1326.     <!-- GetFileExtension is a SharePoint runtime function that takes a string url as input and 
  1327.           output the file extension.-->
  1328.     <xsl:template mode="genTemplates" match="UrlBaseName|GetFileExtension">
  1329.         <xsl:param name="currentView"/>        
  1330.         <xsl:param name="fieldData"/>
  1331.         <xsl:param name="renderPattern"/>
  1332.         <xsl:param name="Field"/>
  1333.  
  1334.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  1335.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  1336.  
  1337.         <xsl:choose>
  1338.             <xsl:when test="$fieldData/@RenderXMLUsingPattern='TRUE' and Field[@Name='EncodedAbsUrl']">
  1339.                 <xsl:text/>{ddwrt:<xsl:value-of select="name(.)"/>(concat($HttpHost, @FileRef))}<xsl:text/>
  1340.             </xsl:when>
  1341.             <xsl:when test="name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = '"'">
  1342.                 <xsl:text/>{ddwrt:<xsl:value-of select="name(.)"/>(<xsl:apply-templates mode="genTemplates" select="*">
  1343.                 <xsl:with-param name="currentView" select="$currentView"/>
  1344.                 <xsl:with-param name="fieldData" select="$fieldData"/>
  1345.                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1346.                 <xsl:with-param name="Field" select="."/>                            
  1347.             </xsl:apply-templates>)}<xsl:text/>
  1348.             </xsl:when>
  1349.             <xsl:when test="ancestor::Expr or ancestor::Expr1 or ancestor::Expr2">
  1350.                 <xsl:text/>ddwrt:<xsl:value-of select="name(.)"/>(<xsl:apply-templates mode="genTemplates" select="*">
  1351.                 <xsl:with-param name="currentView" select="$currentView"/>
  1352.                 <xsl:with-param name="fieldData" select="$fieldData"/>
  1353.                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1354.                 <xsl:with-param name="Field" select="."/>                            
  1355.                 </xsl:apply-templates>)<xsl:text/>
  1356.             </xsl:when>
  1357.             <xsl:when test="*[name() = 'LookupColumn']">
  1358.                 <xz:value-of>
  1359.                     <xsl:attribute name="select">ddwrt:<xsl:value-of select="name(.)"/>(string(@LinkFilename))</xsl:attribute>
  1360.                 </xz:value-of>
  1361.             </xsl:when>
  1362.             <xsl:otherwise>
  1363.                 <xz:value-of>
  1364.                     <xsl:attribute name="select">ddwrt:<xsl:value-of select="name(.)"/>(<xsl:apply-templates mode="genTemplates" select="*">
  1365.                         <xsl:with-param name="currentView" select="$currentView"/>
  1366.                         <xsl:with-param name="fieldData" select="$fieldData"/>
  1367.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1368.                         <xsl:with-param name="Field" select="."/>                            
  1369.                     </xsl:apply-templates>)</xsl:attribute>
  1370.                 </xz:value-of>    
  1371.             </xsl:otherwise>
  1372.         </xsl:choose>
  1373.     </xsl:template>
  1374.  
  1375.     <!-- ThreadStamp is a SharePoint runtime function that returns renders the current server's 
  1376.             local time in a specific     format (yyyyMMddHHmmss) for sorting purposes. -->
  1377.     <xsl:template mode="genTemplates" match="ThreadStamp">
  1378.         <xsl:param name="currentView"/>        
  1379.         <xsl:param name="fieldData"/>
  1380.         <xsl:param name="renderPattern"/>
  1381.         <xsl:param name="Field"/>
  1382.  
  1383.         <xsl:choose>
  1384.             <xsl:when test="ancestor::Expr or ancestor::Expr1 or ancestor::Expr2 or ancestor::Limit">ddwrt:ThreadStamp(<xsl:value-of select="@StripWS"/>)    </xsl:when>
  1385.             <xsl:otherwise>
  1386.                 <xsl:text/>{ddwrt:ThreadStamp(<xsl:value-of select="@StripWS"/>)}<xsl:text/>
  1387.             </xsl:otherwise>
  1388.         </xsl:choose>
  1389.     </xsl:template>
  1390.  
  1391.     <!-- ThreadStamp is a SharePoint runtime function that rgenerates a globally unique identifier 
  1392.           as returned by the Microsoft Component Object Model function CoCreateGuid.    -->
  1393.     <xsl:template mode="genTemplates" match="GUID">
  1394.         <xsl:param name="currentView"/>        
  1395.         <xsl:param name="fieldData"/>
  1396.         <xsl:param name="renderPattern"/>
  1397.         <xsl:param name="Field"/>
  1398.  
  1399.         <xsl:text/>{ddwrt:GUID()}<xsl:text/>
  1400.     </xsl:template>
  1401.  
  1402.     <xsl:template mode="genTemplates-inscript" match="Counter">
  1403.         <xsl:text/><xz:value-of><xsl:attribute name="select">ddwrt:Counter()</xsl:attribute></xz:value-of><xsl:text/>
  1404.     </xsl:template>
  1405.     
  1406.     <xsl:template mode="genTemplates" match="Counter">
  1407.         <xsl:param name="currentView"/>
  1408.         <xsl:param name="fieldData"/>
  1409.         <xsl:param name="renderPattern"/>
  1410.         <xsl:param name="Field"/>
  1411.  
  1412.         <xsl:choose>
  1413.             <xsl:when test="@Type='View'"><xsl:value-of select="$Counter"/></xsl:when>
  1414.             <xsl:otherwise><xsl:text/>{ddwrt:Counter()}<xsl:text/></xsl:otherwise>
  1415.         </xsl:choose>
  1416.     </xsl:template>
  1417.  
  1418.     <xsl:template mode="genTemplates" match="HTML">
  1419.         <xsl:param name="currentView"/>        
  1420.         <xsl:param name="fieldData"/>
  1421.         <xsl:param name="renderPattern"/>
  1422.         
  1423.         <!-- if current node is html node, and it ends with quote, doesn't start with empty space, and 
  1424.               doesn't end with empty space, then we need to normalize-space this node in output! -->
  1425.             <xsl:variable name="Str"     select="string(.)"/>
  1426.             <xsl:variable name="StrText"     select="text()"/>
  1427.             <xsl:variable name="NormalizedStr"     select="normalize-space(string(.))"/>
  1428.             <xsl:choose>
  1429.                 <xsl:when test="Switch">
  1430.                     <xsl:apply-templates mode="genTemplates" select="*">
  1431.                         <xsl:with-param name="currentView" select="$currentView"/>
  1432.                         <xsl:with-param name="fieldData" select="$fieldData"/>
  1433.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1434.                         <xsl:with-param name="Field" select="."/>                            
  1435.                     </xsl:apply-templates>    
  1436.                 </xsl:when>
  1437.                 <xsl:when test="ancestor::ScriptQuote[not(@NotAddingQuote='TRUE')]">
  1438.                     <xz:text script="1">
  1439.                         <xsl:value-of select="text()"/>    
  1440.                     </xz:text>
  1441.                 </xsl:when>
  1442.                 <!-- if we have { in the string, presumably it's script, enclose it with CDATA and
  1443.                      xsl:text tag.-->
  1444.                 <xsl:when test="(contains($StrText, '{') and not (contains($Str, '"{'))) or contains($Str, 'SCRIPT') or
  1445.                                  contains($StrText, '<%') or (contains($StrText, '%>') and not(contains($StrText, '0%>')))">
  1446.                     <xz:text disable-output-escaping="yes">
  1447.                         <xsl:value-of select="text()"/>    
  1448.                     </xz:text>
  1449.                 </xsl:when>
  1450.                 <xsl:when test="contains($StrText, '&') and (contains($StrText, '<>') or contains($StrText, 'SCRIPT>'))">
  1451.                     <xz:text disable-output-escaping="yes">
  1452.                         <xsl:value-of select="text()"/>    
  1453.                     </xz:text>
  1454.                 </xsl:when>
  1455.                 <xsl:when test="(substring($NormalizedStr, string-length($NormalizedStr) - 3, 4) = '<tr>' and
  1456.                                 not(substring($NormalizedStr, 1, 1) = '"')) or
  1457.                                 substring($NormalizedStr, 1, 18)= '</TD></TR><TR><TD ' or
  1458.                                 ($NormalizedStr = '</TR>' and not(position()=last()) and not(name(preceding-sibling::*[1])) = 'Fields') or 
  1459.                                 ($NormalizedStr = '<TR>' and not(position()=1))">
  1460.                     <xz:text disable-output-escaping="yes">
  1461.                         <xsl:value-of select="text()"/>    
  1462.                     </xz:text>
  1463.                 </xsl:when>
  1464.                 <xsl:when test="
  1465.                     (substring($NormalizedStr, string-length($NormalizedStr), 1) = '"' or
  1466.                     substring($NormalizedStr, string-length($NormalizedStr), 1) = $singleQuote) and
  1467.                     not (substring($Str, 1, 1) = ' ') and not(substring($Str, string-length($Str), 1) = ' ')">
  1468.                     
  1469.                         <xsl:value-of select="normalize-space(text())" disable-output-escaping="yes"/>
  1470.                         
  1471.                 </xsl:when>
  1472.                 <xsl:otherwise>
  1473.                     <xsl:value-of select="text()" disable-output-escaping="yes"/>    
  1474.                 </xsl:otherwise>
  1475.             </xsl:choose>
  1476.     </xsl:template>
  1477.  
  1478.     <!--ifnew is not a param, since the value of ifnew depends on the current field
  1479.           being evaluated. It's definitely a runtime function provided by SP code which
  1480.          maintains such state. -->
  1481.     <xsl:template mode="genTemplates" match="IfNew">
  1482.         <xsl:param name="currentView"/>        
  1483.         <xsl:param name="fieldData"/>
  1484.         <xsl:param name="renderPattern"/>
  1485.         <xsl:param name="Field"/>
  1486.  
  1487.         <xz:if test="ddwrt:IfNew(string(@Created))">
  1488.             <xsl:apply-templates mode="genTemplates" select="*">
  1489.                 <xsl:with-param name="currentView" select="$currentView"/>
  1490.                 <xsl:with-param name="fieldData" select="$fieldData"/>
  1491.                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1492.                 <xsl:with-param name="Field" select="."/>                            
  1493.             </xsl:apply-templates>        
  1494.         </xz:if>
  1495.    </xsl:template>
  1496.     
  1497.     <xsl:template mode="genTemplates" match="ProjectProperty">
  1498.         <xsl:param name="currentView"/>        
  1499.         <xsl:param name="fieldData"/>
  1500.         <xsl:param name="renderPattern"/>
  1501.         <xsl:param name="Field"/>
  1502.  
  1503.         <xsl:choose>
  1504.             <xsl:when test="@Select='RecycleBinEnabled'">                
  1505.                 <xz:value-of>
  1506.                     <xsl:attribute name="select">
  1507.                         <xsl:choose>
  1508.                             <xsl:when test="ddwrt:RecycleBinenabled()">1</xsl:when>
  1509.                             <xsl:otherwise>0</xsl:otherwise>
  1510.                         </xsl:choose>
  1511.                     </xsl:attribute>
  1512.                 </xz:value-of>    
  1513.             </xsl:when>
  1514.             <xsl:otherwise><xsl:text/>web<xsl:text/></xsl:otherwise>
  1515.         </xsl:choose>
  1516.     </xsl:template>
  1517.  
  1518.     <xsl:template mode="genTemplates" match="UserID">
  1519.         <xsl:param name="currentView"/>        
  1520.         <xsl:param name="fieldData"/>
  1521.         <xsl:param name="renderPattern"/>
  1522.         <xsl:param name="Field"/>
  1523.  
  1524.         <xsl:choose>
  1525.             <xsl:when test="ancestor::ScriptQuote">
  1526.                 <xsl:text/>{$Userid}<xsl:text/>
  1527.             </xsl:when>
  1528.             <xsl:otherwise>
  1529.                 <xz:value-of>
  1530.                     <xsl:attribute name="select">$Userid</xsl:attribute>
  1531.                 </xz:value-of>    
  1532.             </xsl:otherwise>
  1533.         </xsl:choose>
  1534.         
  1535.     </xsl:template>
  1536.  
  1537.     <xsl:template mode="genTemplates" match="ListProperty">
  1538.         <xsl:param name="currentView"/>        
  1539.         <xsl:param name="fieldData"/>
  1540.         <xsl:param name="renderPattern"/>
  1541.         <xsl:param name="Field"/>
  1542.  
  1543.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  1544.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  1545.         <xsl:variable name="nextStr"     select="normalize-space(string(following-sibling::*[1]))"/>        
  1546.         <xsl:variable name="StrText"     select="$prevNode/text()"/>
  1547.         <xsl:choose>
  1548.             <!-- a heuristic : gleaning of sample caml yields the 
  1549.                 observation that if the htmlencode attribute is set to true, 
  1550.                 we are looking at something outside of a tag, otherwise
  1551.                 part of an attribute value 
  1552.                 an additional heuristic would be to look at the previous sibling and check 
  1553.                 to see whether it was an <HTML> tag that ended in a quote. 
  1554.                 the string in use is normalized.
  1555.                 if the previous node ends with =, then we're inside the <script>tag 
  1556.                 if it's inside the <script> tag, then we need to do the right thing.
  1557.                 One more twist: in <ViewEmpty> tag, it's certain that it's simple text.-->    
  1558.             <!-- if we're inside or beside a <script>-->
  1559.             <xsl:when test="name($prevNode)='HTML' and (contains($StrText, '{') and not (contains($prevStr, '"{'))) or contains($prevStr, 'SCRIPT') or
  1560.                                  contains($StrText, '<%') or contains($StrText, '%>')">
  1561.                 <xz:value-of>
  1562.                     <xsl:attribute name="select">ddwrt:ListProperty('<xsl:value-of select="@Select"/>')</xsl:attribute>
  1563.                 </xz:value-of>    
  1564.             </xsl:when>
  1565.             <xsl:when test="substring($nextStr, 1, 1)=';'">
  1566.                 <xz:value-of>
  1567.                     <xsl:attribute name="select">ddwrt:ListProperty('<xsl:value-of select="@Select"/>')</xsl:attribute>
  1568.                 </xz:value-of>
  1569.             </xsl:when>
  1570.             <xsl:when test="name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = '=' and not(substring($nextStr, 1, 1) = '"') and not(substring($nextStr, 1, 1) = $singleQuote)">
  1571.                 <xsl:apply-templates mode="genTemplates-inscript" select="."/>
  1572.             </xsl:when>                
  1573.             <xsl:when test="(@HTMLEncode = 'TRUE' and not(name($prevNode) = 'HTML' and
  1574.                     (substring($prevStr, string-length($prevStr), 1) = '"' or
  1575.                     substring($prevStr, string-length($prevStr), 1) = $singleQuote))) or
  1576.                     (ancestor::ViewEmpty and not(substring($prevStr, 1, 1) = '<') and 
  1577.                     not(ancestor::Expr or ancestor::Expr1 or ancestor::Expr2)
  1578.                     and not(name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr) - 4, 5) = 'dir="'))">
  1579.                 <xz:value-of>
  1580.                     <xsl:attribute name="select">ddwrt:ListProperty('<xsl:value-of select="@Select"/>')</xsl:attribute>
  1581.                 </xz:value-of>
  1582.             </xsl:when>
  1583.             <xsl:when test="ancestor::Expr or ancestor::Expr1 or ancestor::Expr2">
  1584.                     <xsl:text/>ddwrt:ListProperty('<xsl:value-of select="@Select"/>')<xsl:text/>
  1585.             </xsl:when>
  1586.             <xsl:otherwise>
  1587.                 <xsl:text/>{ddwrt:ListProperty(<xsl:call-template name="ProperEscapedApostrophe" /><xsl:value-of select="@Select"/><xsl:call-template name="ProperEscapedApostrophe" />)}<xsl:text/>
  1588.             </xsl:otherwise>
  1589.         </xsl:choose>
  1590.     </xsl:template>
  1591.         
  1592.     <xsl:template mode="genTemplates-inscript" match="ListProperty">
  1593.         <xsl:param name="currentView"/>        
  1594.         <xsl:param name="fieldData"/>
  1595.         <xsl:param name="renderPattern"/>
  1596.             
  1597.             <xsl:text/>{ddwrt:ListProperty(<xsl:call-template name="ProperEscapedApostrophe" /><xsl:value-of select="@Select"/><xsl:call-template name="ProperEscapedApostrophe" />)}<xsl:text/>
  1598.     </xsl:template>
  1599.         
  1600.     <xsl:template mode="genTemplates-inscript" match="ListUrlDir">
  1601.         <xsl:param name="currentView"/>        
  1602.         <xsl:param name="fieldData"/>
  1603.         <xsl:param name="renderPattern"/>
  1604.                 
  1605.             <xsl:choose>
  1606.                 <xsl:when test="@WebRel">                    
  1607.                     <xz:value-of>
  1608.                         <xsl:attribute name="select">$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="@WebRel"/></xsl:attribute>
  1609.                     </xz:value-of>
  1610.                 </xsl:when>
  1611.                 <xsl:otherwise>
  1612.                     <xz:value-of>
  1613.                         <xsl:attribute name="select">$<xsl:value-of select="name(.)" disable-output-escaping="yes"/></xsl:attribute>
  1614.                     </xz:value-of>
  1615.                 </xsl:otherwise>
  1616.             </xsl:choose>
  1617.         
  1618.     </xsl:template>
  1619.  
  1620.     <xsl:template mode="genTemplates-inscript" match="URL">
  1621.         <xsl:param name="currentView"/>        
  1622.         <xsl:param name="fieldData"/>
  1623.         <xsl:param name="renderPattern"/>
  1624.  
  1625.         <xsl:choose>
  1626.             <xsl:when test="@Cmd='Edit'">{$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="@Cmd"/>}?ID={@ID}</xsl:when>
  1627.             <xsl:otherwise>{$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="@Cmd"/>}</xsl:otherwise>
  1628.         </xsl:choose>                
  1629.     </xsl:template>
  1630.  
  1631.     <xsl:template mode="genTemplates-inscript" match="HTML">
  1632.         <xsl:param name="currentView"/>        
  1633.         <xsl:param name="fieldData"/>
  1634.         <xsl:param name="renderPattern"/>
  1635.  
  1636.  
  1637.         <xsl:choose>
  1638.             <xsl:when test="ancestor::ScriptQuote[@NotAddingQuote='TRUE']">
  1639.                 <xsl:value-of select="text()" disable-output-escaping="yes"/>    
  1640.             </xsl:when>
  1641.             <xsl:otherwise>
  1642.                 <xz:text script="1">
  1643.                     <xsl:value-of select="text()"/>    
  1644.                 </xz:text>
  1645.             </xsl:otherwise>
  1646.         </xsl:choose>
  1647.     </xsl:template>
  1648.         
  1649.     <xsl:template mode="genTemplates-inscript" match="ScriptQuote">
  1650.         <xsl:param name="currentView"/>        
  1651.         <xsl:param name="fieldData"/>
  1652.         <xsl:param name="renderPattern"/>
  1653.             <xsl:if test="not(@NotAddingQuote='TRUE')">
  1654.                 <xsl:choose>
  1655.                     <xsl:when test="ancestor::ScriptQuote">
  1656.                         <xsl:text/>\u0022<xsl:text/>
  1657.                     </xsl:when>
  1658.                     <xsl:otherwise>
  1659.                         <xsl:text disable-output-escaping="yes">"</xsl:text>
  1660.                     </xsl:otherwise>
  1661.                 </xsl:choose>
  1662.             </xsl:if>
  1663.             <xsl:choose>
  1664.                 <xsl:when test="*">
  1665.                     <xsl:apply-templates mode="genTemplates-inscript" select="*">
  1666.                         <xsl:with-param name="currentView" select="$currentView"/>
  1667.                         <xsl:with-param name="fieldData" select="$fieldData"/>
  1668.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1669.                         <xsl:with-param name="Field" select="."/>                            
  1670.                     </xsl:apply-templates>                    
  1671.                 </xsl:when>
  1672.                 <xsl:otherwise>
  1673.                     <xsl:value-of select="."/>
  1674.                 </xsl:otherwise>
  1675.             </xsl:choose>
  1676.             <xsl:if test="not(@NotAddingQuote='TRUE')">
  1677.                 <xsl:choose>
  1678.                     <xsl:when test="ancestor::ScriptQuote">
  1679.                         <xsl:text/>\u0022<xsl:text/>
  1680.                     </xsl:when>
  1681.                     <xsl:otherwise>
  1682.                         <xsl:text disable-output-escaping="yes">"</xsl:text>
  1683.                     </xsl:otherwise>
  1684.                 </xsl:choose>
  1685.             </xsl:if>
  1686.     </xsl:template>
  1687.     
  1688.     <!-- default is to call the regular one -->
  1689.     <xsl:template mode="genTemplates-inscript" match="*">
  1690.         <xsl:param name="currentView"/>        
  1691.         <xsl:param name="fieldData"/>
  1692.         <xsl:param name="renderPattern"/>
  1693.         <xsl:apply-templates mode="genTemplates" select=".">
  1694.             <xsl:with-param name="currentView" select="$currentView"/>
  1695.             <xsl:with-param name="fieldData" select="$fieldData"/>
  1696.             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1697.             <xsl:with-param name="Field" select="."/>
  1698.         </xsl:apply-templates>
  1699.     </xsl:template>        
  1700.     
  1701.     <xsl:template mode="genTemplates-inscript" match="LocaleInfo">
  1702.         <xsl:param name="currentView"/>        
  1703.         <xsl:param name="fieldData"/>
  1704.         <xsl:param name="renderPattern"/>
  1705.                 
  1706.         <xsl:text/><xz:value-of><xsl:attribute name="select">$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="@LCTYPE"/></xsl:attribute></xz:value-of><xsl:text/>
  1707.     </xsl:template>
  1708.  
  1709. <!-- current thinking has getvar being a runtime function        
  1710. -->
  1711.     <xsl:template mode="genTemplates-inscript" match="GetVar">
  1712.         <xsl:choose>
  1713.         <xsl:when test="ancestor::ScriptQuote[@NotAddingQuote='TRUE']">{ddwrt:GetVar(<xsl:text disable-output-escaping="yes">&apos;</xsl:text><xsl:value-of select="@Name"/><xsl:text disable-output-escaping="yes">&apos;</xsl:text>)}</xsl:when>
  1714.         <xsl:otherwise>
  1715.             <xz:value-of>
  1716.                 <xsl:attribute name="select">ddwrt:GetVar('<xsl:value-of select="@Name"/>')</xsl:attribute>
  1717.             </xz:value-of>
  1718.         </xsl:otherwise>
  1719.         </xsl:choose>
  1720.     </xsl:template>
  1721.         
  1722.     <xsl:template mode="genTemplates-inscript" match="FieldPrefix">urn:schemas-microsoft-com:office:office#</xsl:template>
  1723.     <xsl:template mode="genTemplates" match="FieldPrefix">urn:schemas-microsoft-com:office:office#</xsl:template>
  1724.  
  1725.     <xsl:template mode="genTemplates-inscript" match="HttpVDir|ImagesPath|HttpPath|List|ID|Identity">
  1726.         <xsl:param name="currentView"/>        
  1727.         <xsl:param name="fieldData"/>
  1728.         <xsl:param name="renderPattern"/>
  1729.         
  1730.             <xsl:text/>{$<xsl:value-of select="name(.)"/>}<xsl:text/>
  1731.  
  1732.     </xsl:template>
  1733.         
  1734.         
  1735.     <xsl:template mode="genTemplates" match="WebQueryInfo">
  1736.         <xsl:choose>
  1737.         <xsl:when test="ancestor::ScriptQuote">
  1738.             <xsl:text/>{$List}-{$View} Summary={$List} xmlns:o=urn:schemas-microsoft-com:office:office o:WebQuerySourceHref={$HttpPath}<xz:text disable-output-escaping="yes">&XMLDATA=1&RowLimit=0&</xz:text>View={$View}<xsl:text/>
  1739.         </xsl:when>
  1740.         <xsl:otherwise>
  1741.             <xsl:text/>{$List}-{$View}" Summary="{$List}" xmlns:o="urn:schemas-microsoft-com:office:office" o:WebQuerySourceHref="{$HttpPath}&XMLDATA=1&RowLimit=0&View={$View}<xsl:text/>
  1742.         </xsl:otherwise>    
  1743.         </xsl:choose>
  1744.     </xsl:template>    
  1745.     
  1746.     <xsl:template mode="genTemplates" match="HttpVDir|ImagesPath|HttpPath|List|ID|FilterLink|PageUrl|URL">
  1747.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  1748.         <xsl:variable name="prevStr"     select="normalize-space(string($prevNode))"/>
  1749.         <xsl:variable name="StrText"     select="$prevNode/text()"/>
  1750.  
  1751.         <xsl:choose>
  1752.             <!-- a heuristic : gleaning of sample caml yields the 
  1753.                 observation that if the htmlencode attribute is set to true, 
  1754.                 we are looking at something outside of a tag, otherwise
  1755.                 part of an attribute value 
  1756.                 an additional heuristic would be to look at the previous sibling and check 
  1757.                 to see whether it was an <HTML> tag that ended in a quote. 
  1758.                 the string in use is normalized.
  1759.                 if the previous node ends with =, then we're inside the <script>tag 
  1760.                 
  1761.                 one more thing: if the var is inside listformopening node, it means it's probably
  1762.                 inside script, except that we're passed </script>, which means the node is preceded
  1763.                 by some <form or <input tag.-->    
  1764.             <xsl:when test="ancestor::ListFormOpening and not(substring-after($prevStr, '<Form')
  1765.                         or substring-after($prevStr, '<INPUT')) or 
  1766.                         ((parent::Then or parent::Else or parent::Case or parent::Default) and not(preceding-sibling::*[1]))">
  1767.                 <xz:value-of>
  1768.                     <xsl:attribute name="select">$<xsl:value-of select="name(.)" disable-output-escaping="yes"/></xsl:attribute>
  1769.                 </xz:value-of>
  1770.             </xsl:when>
  1771.             <xsl:otherwise>{$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>}</xsl:otherwise>
  1772.         </xsl:choose>    
  1773.     </xsl:template>
  1774.  
  1775.  
  1776.     <!-- Same as before except that the name also incldes the field name.-->
  1777.     <xsl:template mode="genTemplates" match="FieldFilterImageURL">
  1778.         <xsl:param name="currentView"/>
  1779.         <xsl:param name="fieldData"/>
  1780.         <xsl:param name="renderPattern"/>
  1781.         <xsl:param name="Field"/>
  1782.         <xsl:param name="ThisField"/>                    
  1783.  
  1784.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  1785.         <xsl:choose>
  1786.             <xsl:when test="ancestor::ListFormOpening and not(substring-after($prevStr, '<Form')
  1787.                         or substring-after($prevStr, '<INPUT'))">
  1788.                 <xz:value-of>
  1789.                     <xsl:attribute name="select">$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="$fieldData/@Name" disable-output-escaping="yes"/></xsl:attribute>
  1790.                 </xz:value-of>
  1791.             </xsl:when>
  1792.             <xsl:otherwise><xsl:text/>{ddwrt:FieldFilterImageUrl('<xsl:value-of select="$fieldData/@Name" disable-output-escaping="yes"/>')}<xsl:text/></xsl:otherwise>
  1793.         </xsl:choose>
  1794.     </xsl:template>
  1795.  
  1796.     <!-- Same as before except that the name also incldes the field name.-->
  1797.     <xsl:template mode="genTemplates" match="FieldSortImageURL">
  1798.         <xsl:param name="currentView"/>
  1799.         <xsl:param name="fieldData"/>
  1800.         <xsl:param name="renderPattern"/>
  1801.         <xsl:param name="Field"/>
  1802.         <xsl:param name="ThisField"/>                    
  1803.  
  1804.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  1805.         <xsl:choose>
  1806.             <xsl:when test="ancestor::ListFormOpening and not(substring-after($prevStr, '<Form')
  1807.                         or substring-after($prevStr, '<INPUT'))">
  1808.                 <xz:value-of>
  1809.                     <xsl:attribute name="select">$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="$fieldData/@Name" disable-output-escaping="yes"/></xsl:attribute>
  1810.                 </xz:value-of>
  1811.             </xsl:when>
  1812.             <xsl:otherwise><xsl:text/>{ddwrt:FieldSortImageUrl('<xsl:value-of select="$fieldData/@Name" disable-output-escaping="yes"/>')}<xsl:text/></xsl:otherwise>
  1813.         </xsl:choose>
  1814.     </xsl:template>
  1815.  
  1816.     <!-- Field sort param will be replaced by our DDW sort stuffs, so just output nothing. -->
  1817.     <xsl:template mode="genTemplates" match="FieldSortParams">
  1818.         <xsl:param name="currentView"/>
  1819.         <xsl:param name="fieldData"/>
  1820.         <xsl:param name="renderPattern"/>
  1821.         <xsl:param name="Field"/>
  1822.         <xsl:param name="ThisField"/>                    
  1823.  
  1824.     </xsl:template>
  1825.  
  1826.     <xsl:template mode="genTemplates-inscript" match="LookupColumn">
  1827.         <!-- for stuffs inside urlencode, we just do the {$}, otherwise the full swing-->
  1828.         <xsl:choose>
  1829.             <xsl:when test="ancestor::ScriptQuote[@NotAddingQuote='TRUE']">{@<xsl:value-of select="@ShowField"/>}</xsl:when>
  1830.             <xsl:when test="not(ancestor::URLEncode)">{@<xsl:value-of select="name(.)"/>}<xsl:text/></xsl:when>
  1831.             <xsl:otherwise>
  1832.                 <xz:value-of>
  1833.                     <xsl:attribute name="select">
  1834.                         <xsl:text/>/dsQueryResponse/<xsl:value-of select="$resultRoot"/>/<xsl:value-of select="$resultRow"/>[@ID = $ID]/@<xsl:value-of select="@Name"/><xsl:text/>
  1835.                     </xsl:attribute>
  1836.                 </xz:value-of>
  1837.             </xsl:otherwise>
  1838.         </xsl:choose>
  1839.         
  1840.     </xsl:template>
  1841.  
  1842.     <xsl:template mode="genTemplates" match="HttpHost">
  1843.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  1844.         
  1845.         <xsl:choose>
  1846.             <!--an additional heuristic would be to look at the previous sibling and check 
  1847.                 to see whether it was an <HTML> tag that ended in a quote. 
  1848.                 the string in use is normalized.
  1849.                 if the previous node ends with =, then we're inside the <script>tag 
  1850.                 
  1851.                 one more thing: if the var is inside listformopening node, it means it's probably
  1852.                 inside script, except that we're passed </script>, which means the node is preceded
  1853.                 by some <form or <input tag.-->    
  1854.             <xsl:when test="ancestor::ListFormOpening and not(substring-after($prevStr, '<Form')
  1855.                         or substring-after($prevStr, '<INPUT')) or ((ancestor::URLEncode) and $isAViewAndNotAForm = '0')
  1856.                         or ((parent::Then or parent::Else or parent::Case or parent::Default) and not(preceding-sibling::*[1]))">
  1857.                 <xz:value-of>
  1858.                     <xsl:attribute name="select">$<xsl:value-of select="name(.)" disable-output-escaping="yes"/></xsl:attribute>
  1859.                 </xz:value-of>
  1860.             </xsl:when>
  1861.             <xsl:when test="ancestor::SetVar">
  1862.                 <xsl:text/>$<xsl:value-of select="name(.)" disable-output-escaping="yes"/><xsl:text/>
  1863.             </xsl:when>
  1864.             <xsl:otherwise>{$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>}</xsl:otherwise>
  1865.         </xsl:choose>    
  1866.     </xsl:template>
  1867.  
  1868.     <!-- these are special "prerendered" caml tags -->        
  1869.     <xsl:template mode="genTemplates" match="Identity">
  1870.             <xz:value-of><xsl:attribute name="select">$<xsl:value-of select="name(.)" disable-output-escaping="yes"/></xsl:attribute></xz:value-of>
  1871.     </xsl:template>
  1872.         
  1873.     <!-- localeInfo should be inside the <script>tag -->
  1874.     <xsl:template mode="genTemplates" match="LocaleInfo">
  1875.         <xsl:text/><xz:value-of><xsl:attribute name="select">$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="@LCTYPE"/></xsl:attribute></xz:value-of><xsl:text/>
  1876.     </xsl:template>
  1877.  
  1878.     <xsl:template mode="genTemplates" match="Fields">
  1879.         <xsl:param name="currentView"/>        
  1880.         <xsl:param name="fieldData"/>
  1881.         <xsl:param name="renderPattern"/>
  1882.         <xsl:param name="Field"/>
  1883.         
  1884.         <!-- save this tag in a variable -->
  1885.         <xsl:variable name="thisFieldsNode" select="."/>
  1886.         <xsl:variable name="formIsNotReadOnly" select="not($isAViewAndNotAForm = '1')"/>
  1887.                             
  1888.         <!-- for each field -->
  1889.         <xsl:choose>
  1890.             <xsl:when test="$currentView/ViewFields">                
  1891.                 <xsl:choose>
  1892.                 <xsl:when test="Switch/Expr/GetVar[@Name='First']">
  1893.                     <xsl:for-each select="$currentView/ViewFields/FieldRef[position() = 1 and not(@Name = $currentView/ViewBody//FieldProperty/@Name) and not (@Name = $currentView/ViewBody//Field/@Name)]">
  1894.                     <xsl:variable name="currentField" select="/List/MetaData/Fields/Field[@Name=current()/@Name]"/>                    
  1895.                     <xsl:comment><xsl:value-of select="@Name"/></xsl:comment>
  1896.                     <xsl:comment><xsl:value-of select="/List/MetaData/Fields/Field[@Name=current()/@Name]/@DisplayName"/></xsl:comment>
  1897.                     <xsl:choose>
  1898.                         <xsl:when test="$thisFieldsNode/Switch/Case[@Value='1']">
  1899.                             <xsl:apply-templates mode="expandCAML" select="$thisFieldsNode/Switch/Case">
  1900.                                 <xsl:with-param name="currentView" select="$currentView"/>
  1901.                                 <xsl:with-param name="currentField" select="$currentField"/>
  1902.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1903.                                 <xsl:with-param name="Field" select="$Field"/>
  1904.                             </xsl:apply-templates>                
  1905.                         </xsl:when>
  1906.                         <xsl:otherwise>
  1907.                             <xsl:apply-templates mode="expandCAML" select="$thisFieldsNode/Switch/Default">
  1908.                                 <xsl:with-param name="currentView" select="$currentView"/>
  1909.                                 <xsl:with-param name="currentField" select="$currentField"/>
  1910.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1911.                                 <xsl:with-param name="Field" select="$Field"/>
  1912.                             </xsl:apply-templates>                
  1913.                         </xsl:otherwise>                        
  1914.                     </xsl:choose>    
  1915.                     
  1916.                     <xsl:apply-templates mode="genTemplates" select="$thisFieldsNode/Field">
  1917.                         <xsl:with-param name="currentView" select="$currentView"/>
  1918.                         <xsl:with-param name="fieldData" select="$currentField"/>
  1919.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1920.                         <xsl:with-param name="Field" select="$Field"/>
  1921.                     </xsl:apply-templates>                
  1922.  
  1923.                     </xsl:for-each>    
  1924.                     
  1925.                     <xsl:for-each select="$currentView/ViewFields/FieldRef[not(position() = 1) and not(@Explicit='TRUE')]">
  1926.                     <xsl:variable name="currentField" select="/List/MetaData/Fields/Field[@Name=current()/@Name]"/>
  1927.                     <xsl:comment><xsl:value-of select="@Name"/></xsl:comment>
  1928.                     <xsl:comment><xsl:value-of select="/List/MetaData/Fields/Field[@Name=current()/@Name]/@DisplayName"/></xsl:comment>
  1929.                     <xsl:choose>
  1930.                         <xsl:when test="$thisFieldsNode/Switch/Case[@Value='1']">
  1931.                             <xsl:apply-templates mode="expandCAML" select="$thisFieldsNode/Switch/Default">
  1932.                                 <xsl:with-param name="currentView" select="$currentView"/>
  1933.                                 <xsl:with-param name="currentField" select="$currentField"/>
  1934.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1935.                                 <xsl:with-param name="Field" select="$Field"/>
  1936.                             </xsl:apply-templates>                
  1937.                         </xsl:when>
  1938.                         <xsl:otherwise>
  1939.                             <xsl:apply-templates mode="expandCAML" select="$thisFieldsNode/Switch/Case">
  1940.                                 <xsl:with-param name="currentView" select="$currentView"/>
  1941.                                 <xsl:with-param name="currentField" select="$currentField"/>
  1942.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1943.                                 <xsl:with-param name="Field" select="$Field"/>
  1944.                             </xsl:apply-templates>                
  1945.                         </xsl:otherwise>                        
  1946.                     </xsl:choose>
  1947.                     
  1948.                     <xsl:apply-templates mode="genTemplates" select="$thisFieldsNode/Field">
  1949.                         <xsl:with-param name="currentView" select="$currentView"/>
  1950.                         <xsl:with-param name="fieldData" select="$currentField"/>
  1951.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1952.                         <xsl:with-param name="Field" select="$Field"/>
  1953.                     </xsl:apply-templates>                
  1954.                     </xsl:for-each>                    
  1955.                     
  1956.                 </xsl:when>
  1957.                 <xsl:otherwise>
  1958.                 <xsl:for-each select="$currentView/ViewFields/FieldRef[not(@Explicit='TRUE')]">
  1959.                     <xsl:variable name="currentField" select="/List/MetaData/Fields/Field[@Name=current()/@Name]"/>
  1960.                     <xsl:comment><xsl:value-of select="@Name"/></xsl:comment>
  1961.                     <xsl:comment><xsl:value-of select="/List/MetaData/Fields/Field[@Name=current()/@Name]/@DisplayName"/></xsl:comment>
  1962.                     <xsl:apply-templates mode="expandCAML" select="$thisFieldsNode">
  1963.                         <xsl:with-param name="currentView" select="$currentView"/>
  1964.                         <xsl:with-param name="currentField" select="$currentField"/>
  1965.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1966.                         <xsl:with-param name="Field" select="$Field"/>
  1967.                 </xsl:apply-templates>                
  1968.                 </xsl:for-each>
  1969.                 </xsl:otherwise>
  1970.                 </xsl:choose>
  1971.             </xsl:when>
  1972.             <xsl:otherwise>
  1973.                 <xsl:for-each select=
  1974.                     "    /List/MetaData/Fields/Field[
  1975.                                                 (    not($currentView/ViewFields) 
  1976.                                                 or    $currentView/ViewFields/FieldRef[@Name= ./@Name])
  1977.                                         and    (    not($formIsNotReadOnly) 
  1978.                                                 or    not(@ReadOnly='TRUE'))
  1979.                                         and    (not(@Hidden = 'TRUE'))]">
  1980.  
  1981.                     <!-- make sure the name is only those in the viewfields -->
  1982.                     <xsl:variable name="currentField" select="."/>
  1983.                     <xsl:comment><xsl:value-of select="@Name"/></xsl:comment>
  1984.                     <xsl:comment><xsl:value-of select="@DisplayName"/></xsl:comment>
  1985.                     <!-- eval this field using the expandCAML template -->
  1986.                     <xsl:apply-templates mode="expandCAML" select="$thisFieldsNode">
  1987.                         <xsl:with-param name="currentView" select="$currentView"/>
  1988.                         <xsl:with-param name="currentField" select="."/>
  1989.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  1990.                         <xsl:with-param name="Field" select="$Field"/>                
  1991.                     </xsl:apply-templates>
  1992.                 </xsl:for-each>            
  1993.             </xsl:otherwise>
  1994.         </xsl:choose>
  1995.  
  1996.     </xsl:template>
  1997.     
  1998.     <xsl:template mode="expandCAML" match="Fields|Case|Default">
  1999.         <xsl:param name="currentView"/>        
  2000.         <xsl:param name="currentField"/>
  2001.         <xsl:param name="renderPattern"/>
  2002.         <xsl:param name="Field"/>
  2003.         <xsl:apply-templates mode="genTemplates" select="*">
  2004.             <xsl:with-param name="currentView" select="$currentView"/>
  2005.             <xsl:with-param name="fieldData" select="$currentField"/>
  2006.             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2007.             <xsl:with-param name="Field" select="$Field"/>                        
  2008.         </xsl:apply-templates>
  2009.     </xsl:template>
  2010.     
  2011.     <!-- genTemplatesInFields generally just falls through to genTemplates
  2012.         but in some cases (Property) we want to handle it specially -->
  2013. <!--
  2014.     <xsl:template mode="genTemplates" match="*">
  2015.         <xsl:param name="currentView"/>        
  2016.         <xsl:param name="fieldData"/>
  2017.         <xsl:apply-templates mode="genTemplates" select=".">
  2018.             <xsl:with-param name="currentView" select="$currentView"/>
  2019.             <xsl:with-param name="fieldData" select="$fieldData"/>
  2020.         </xsl:apply-templates>
  2021.     </xsl:template>
  2022. -->
  2023.     <xsl:template mode="genTemplates" match="Switch|FieldSwitch">
  2024.         <xsl:param name="currentView"/>        
  2025.         <xsl:param name="fieldData"/>
  2026.         <xsl:param name="renderPattern"/>    
  2027.         <xsl:param name="Field"/>
  2028.     
  2029.         <xsl:variable name="expr" select="Expr"/>
  2030.         <xsl:variable name="Str"     select="string(preceding-sibling::*[1])"/>        
  2031.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  2032.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  2033.  
  2034.         <!-- if the value of the Expr tag is a GetVar, then we have 
  2035.         to do runtime evaluation of the switch. If, however, the value
  2036.         is a Property (and we have a valid fieldData) then we can do 
  2037.         immediate evaluation of the switch and write the result to our
  2038.         output xsl. We need to do this for the sake of certain CAML
  2039.         for FieldSortImageURL, it means we're inside the <img > tag,
  2040.         so we handle it differently, using param.
  2041.           -->
  2042.         <xsl:choose>
  2043.             <xsl:when test="name(preceding-sibling::*[2]) = 'FieldSortImageURL' or name(preceding-sibling::*[1])='ImagesPath'">{$<xsl:value-of select="generate-id(.)"/>}</xsl:when>
  2044.             <xsl:when test="name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = '"' and not (substring($Str, string-length($Str), 1) = ' ')">
  2045.                 <xsl:text/>{$<xsl:value-of select="generate-id(.)"/>}<xsl:text/>
  2046.             </xsl:when>
  2047.             <xsl:when test="name(ancestor::*[1])='ViewBody' and not(preceding-sibling::*[1])">
  2048.                 <xsl:text/>{$<xsl:value-of select="generate-id(.)"/>}<xsl:text/>
  2049.             </xsl:when>
  2050.             <xsl:when test="name($prevNode) = 'HTML' and (substring($prevStr, string-length($prevStr), 1) = $singleQuote or substring($prevStr, string-length($prevStr)-6, 7)='images/')">
  2051.                 <xsl:text/>{$<xsl:value-of select="generate-id(.)"/>}<xsl:text/>
  2052.             </xsl:when>
  2053.             <xsl:when test="Expr/GetVar/@Name='CalView' or Expr/GetVar/@Name='GridView' or Expr/GetVar/@Name='OrderedView'">
  2054.                 <xsl:choose>
  2055.                     <xsl:when test="(Case[@Value='1'])">
  2056.                         <xsl:apply-templates mode="genTemplates" select="Default/*">
  2057.                             <xsl:with-param name="currentView" select="$currentView"/>
  2058.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  2059.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2060.                             <xsl:with-param name="Field" select="$Field"/>
  2061.                         </xsl:apply-templates>
  2062.                     </xsl:when>
  2063.                     <xsl:otherwise>
  2064.                         <xsl:apply-templates mode="genTemplates" select="Case/*">
  2065.                             <xsl:with-param name="currentView" select="$currentView"/>
  2066.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  2067.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2068.                             <xsl:with-param name="Field" select="$Field"/>
  2069.                         </xsl:apply-templates>                                        
  2070.                     </xsl:otherwise>
  2071.                 </xsl:choose>
  2072.             </xsl:when>
  2073.             <xsl:when test="$fieldData and Expr/Property and not($fieldData/@Type='Lookup')">
  2074.                 <xsl:variable name="propName" select="Expr/Property/@Select"/>
  2075.                 <xsl:variable name="switchExprValue" select="string($fieldData/@*[name() = $propName])"/>
  2076.                 <!-- look at the when tags and see if we have a match. -->
  2077.                 <xsl:variable name="evalWhens" select="Case[@Value = $switchExprValue]"/>
  2078.                 <xsl:for-each select="Case">
  2079.                     <xsl:if test="@Value = $switchExprValue">
  2080.                         <xsl:apply-templates mode="genTemplates" select="*">
  2081.                             <xsl:with-param name="currentView" select="$currentView"/>
  2082.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  2083.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2084.                             <xsl:with-param name="Field" select="$Field"/>
  2085.                         </xsl:apply-templates>
  2086.                     </xsl:if>
  2087.                 </xsl:for-each>
  2088.                 
  2089.                 <xsl:if test="not($evalWhens)">
  2090.                     <xsl:choose>
  2091.                     <xsl:when test="Default/*">
  2092.                     <xsl:apply-templates mode="genTemplates" select="Default/*">
  2093.                         <xsl:with-param name="currentView" select="$currentView"/>
  2094.                         <xsl:with-param name="fieldData" select="$fieldData"/>
  2095.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2096.                         <xsl:with-param name="Field" select="$Field"/>
  2097.                     </xsl:apply-templates>
  2098.                     </xsl:when>
  2099.                     <xsl:otherwise>
  2100.                         <xsl:value-of select="Default"/>
  2101.                     </xsl:otherwise>
  2102.                     </xsl:choose>
  2103.                 </xsl:if>
  2104.             </xsl:when>
  2105.             <xsl:when test="Expr/GetVar[@Name='FreeForm'] and count(Expr/*) = 1">
  2106.                 <xsl:choose>
  2107.                     <xsl:when test="(Case[@Value='TRUE'] and $FreeForm='0') or
  2108.                                     (Case[@Value='FALSE'] and $FreeForm='1')">
  2109.                         <xsl:choose>
  2110.                         <xsl:when test="Default/*">
  2111.                         <xsl:apply-templates mode="genTemplates" select="Default/*">
  2112.                             <xsl:with-param name="currentView" select="$currentView"/>
  2113.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  2114.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2115.                             <xsl:with-param name="Field" select="$Field"/>
  2116.                         </xsl:apply-templates>
  2117.                         </xsl:when>
  2118.                         <xsl:otherwise>
  2119.                             <xsl:value-of select="Default"/>
  2120.                         </xsl:otherwise>
  2121.                         </xsl:choose>
  2122.                     </xsl:when>
  2123.                     <xsl:otherwise>
  2124.                         <xsl:apply-templates mode="genTemplates" select="Case/*">
  2125.                             <xsl:with-param name="currentView" select="$currentView"/>
  2126.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  2127.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2128.                             <xsl:with-param name="Field" select="$Field"/>
  2129.                         </xsl:apply-templates>                    
  2130.                     </xsl:otherwise>
  2131.                 </xsl:choose>
  2132.             </xsl:when>
  2133.             <!-- below is the version where we basically convert the switch tag to the xsl
  2134.             equivalent, the choose tag -->
  2135.             <xsl:otherwise>
  2136.                 <xz:choose>
  2137.                 <xsl:for-each select="Case">
  2138.                     <xz:when>
  2139.                         <xsl:attribute name="test">
  2140.                             <xsl:choose>
  2141.                                 <xsl:when test="count($expr/*) > 1">
  2142.                                     <xsl:text/>concat(<xsl:for-each select="$expr/*"><xsl:apply-templates mode="genTemplates" select="."><xsl:with-param name="currentView" select="$currentView"/><xsl:with-param name="fieldData" select="$fieldData"/></xsl:apply-templates><xsl:if test="not(position() = last())">,</xsl:if></xsl:for-each>)='<xsl:value-of select="@Value"/>'<xsl:text/>
  2143.                                 </xsl:when>
  2144.                                 <xsl:otherwise>
  2145.                                     <xsl:choose>
  2146.                                         <xsl:when test="$expr/*"><xsl:apply-templates mode="genTemplates" select="$expr/*"><xsl:with-param name="currentView" select="$currentView"/><xsl:with-param name="fieldData" select="$fieldData"/></xsl:apply-templates>='<xsl:value-of select="@Value"/>'<xsl:text/></xsl:when>
  2147.                                         <xsl:otherwise>'<xsl:value-of select="$expr"/>'='<xsl:value-of select="@Value"/>'<xsl:text/></xsl:otherwise>
  2148.                                     </xsl:choose>
  2149.                                 </xsl:otherwise>
  2150.                             </xsl:choose>
  2151.                         </xsl:attribute>
  2152.                         <xsl:choose>
  2153.                         <xsl:when test="*">
  2154.                             <xsl:apply-templates mode="genTemplates" select="*">
  2155.                                 <xsl:with-param name="currentView" select="$currentView"/>
  2156.                                 <xsl:with-param name="fieldData" select="$fieldData"/>
  2157.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2158.                                 <xsl:with-param name="Field" select="$Field"/>
  2159.                             </xsl:apply-templates>
  2160.                         </xsl:when>
  2161.                         <xsl:otherwise>
  2162.                             <xsl:value-of select="."/>
  2163.                         </xsl:otherwise>
  2164.                         </xsl:choose>
  2165.                     </xz:when>
  2166.                 </xsl:for-each>
  2167.                 <xsl:for-each select="Default">
  2168.                     <xz:otherwise>
  2169.                         <xsl:choose>
  2170.                         <xsl:when test="*">
  2171.                             <xsl:apply-templates mode="genTemplates" select="*">
  2172.                                 <xsl:with-param name="currentView" select="$currentView"/>
  2173.                                 <xsl:with-param name="fieldData" select="$fieldData"/>
  2174.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2175.                                 <xsl:with-param name="Field" select="$Field"/>
  2176.                             </xsl:apply-templates>
  2177.                         </xsl:when>
  2178.                         <xsl:otherwise>
  2179.                             <xsl:value-of select="."/>
  2180.                         </xsl:otherwise>
  2181.                         </xsl:choose>
  2182.                     </xz:otherwise>
  2183.                 </xsl:for-each>
  2184.                 </xz:choose>
  2185.             </xsl:otherwise>
  2186.         </xsl:choose>
  2187.     </xsl:template>
  2188.  
  2189.     <xsl:template mode="genTemplates" match="SetVar">
  2190.         <xsl:param name="currentView"/>        
  2191.         <xsl:param name="fieldData"/>
  2192.         <xsl:param name="renderPattern"/>
  2193.         <xsl:param name="Field"/>
  2194.  
  2195.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  2196.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  2197.         
  2198.         <xsl:choose>
  2199.             <xsl:when test="ancestor::SetVar and @Name='RootFolder'"><xz:value-of select="$PagePath"/>?RootFolder=<xsl:for-each select="LookupColumn"><xsl:apply-templates mode="genTemplates" select=".">
  2200.                     <xsl:with-param name="currentView" select="$currentView"/>
  2201.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  2202.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2203.                     <xsl:with-param name="Field" select="$Field"/>
  2204.                 </xsl:apply-templates></xsl:for-each>&FolderCTID=<xz:value-of select="@ContentTypeId"/></xsl:when>
  2205.             <xsl:when test="SetVar">
  2206.                 <xz:variable>
  2207.                     <xsl:attribute name="name">SetVar<xsl:value-of select="generate-id(.)"/></xsl:attribute>
  2208.                     <xsl:for-each select="SetVar[@Name='RootFolder']">
  2209.                         <xsl:apply-templates mode="genTemplates" select=".">
  2210.                             <xsl:with-param name="currentView" select="$currentView"/>
  2211.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  2212.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2213.                             <xsl:with-param name="Field" select="$Field"/>
  2214.                         </xsl:apply-templates>                                                    
  2215.                     </xsl:for-each>
  2216.                 </xz:variable>
  2217.                 
  2218.                 <xz:value-of>
  2219.                     <xsl:attribute name="select">
  2220.                         <xsl:text/>ddwrt:SetVar('<xsl:value-of select="@Name"/>', string($SetVar<xsl:value-of select="generate-id(.)"/>))<xsl:text/>
  2221.                     </xsl:attribute>
  2222.                 </xz:value-of>                
  2223.             </xsl:when>
  2224.             <!-- if we're inside a quote, that means we can't put <xsl:value-of> stuffs, instead we need to
  2225.                       use a variable, which fortunately has been defined by us.-->
  2226.             <xsl:when test="name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = '"'">
  2227.                 <xsl:apply-templates mode="genTemplates" select="*">
  2228.                     <xsl:with-param name="currentView" select="$currentView"/>
  2229.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  2230.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2231.                     <xsl:with-param name="Field" select="$Field"/>                        
  2232.                 </xsl:apply-templates>
  2233.             </xsl:when>
  2234.             <xsl:when test="ListUrlDir"> <!--this is a string, so don't put '' around. -->
  2235.                 <xz:value-of>
  2236.                     <xsl:attribute name="select">
  2237.                         <xsl:text/>ddwrt:SetVar('<xsl:value-of select="@Name"/>', $ListUrlDir)<xsl:text/>
  2238.                     </xsl:attribute>
  2239.                 </xz:value-of>                
  2240.             </xsl:when>
  2241.             <xsl:when test="GetVar">
  2242.                 <xz:value-of>
  2243.                     <xsl:attribute name="select">
  2244.                         <xsl:text/>ddwrt:SetVar('<xsl:value-of select="@Name"/>', concat(<xsl:for-each select="*"><xsl:apply-templates mode="genTemplates" select="."/><xsl:if test="not(position() = last())">,</xsl:if></xsl:for-each>))<xsl:text/>
  2245.                     </xsl:attribute>
  2246.                 </xz:value-of>                
  2247.             </xsl:when>
  2248.             <xsl:when test="*">
  2249.                 <xsl:choose>
  2250.                     <xsl:when test="Length">
  2251.                         <xz:value-of>
  2252.                             <xsl:attribute name="select">
  2253.                                 <xsl:text/>ddwrt:SetVar('<xsl:value-of select="@Name"/>', string(<xsl:text/><xsl:apply-templates mode="genTemplates" select="child::node()">
  2254.                                     <xsl:with-param name="currentView" select="$currentView"/>
  2255.                                     <xsl:with-param name="fieldData" select="$fieldData"/>
  2256.                                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2257.                                     <xsl:with-param name="Field" select="$Field"/>                        
  2258.                                 </xsl:apply-templates>
  2259.                                 <xsl:text/>))<xsl:text/>
  2260.                             </xsl:attribute>
  2261.                         </xz:value-of>
  2262.                     </xsl:when>
  2263.                     <xsl:otherwise>
  2264.                         <xz:value-of>
  2265.                             <xsl:attribute name="select">
  2266.                                 <xsl:text/>ddwrt:SetVar('<xsl:value-of select="@Name"/>', '<xsl:text/><xsl:apply-templates mode="genTemplates" select="child::node()">
  2267.                                     <xsl:with-param name="currentView" select="$currentView"/>
  2268.                                     <xsl:with-param name="fieldData" select="$fieldData"/>
  2269.                                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2270.                                     <xsl:with-param name="Field" select="$Field"/>                        
  2271.                                 </xsl:apply-templates>
  2272.                                 <xsl:text/>')<xsl:text/>
  2273.                             </xsl:attribute>
  2274.                         </xz:value-of>
  2275.                     </xsl:otherwise>
  2276.                 </xsl:choose>
  2277.             </xsl:when>
  2278.             <xsl:otherwise>
  2279.                 <xz:variable>
  2280.                     <xsl:attribute name="name">Var<xsl:value-of select="generate-id(.)"/></xsl:attribute>
  2281.                     <xsl:attribute name="select">
  2282.                         <xsl:text/>ddwrt:SetVar('<xsl:value-of select="@Name"/>', '<xsl:choose><xsl:when test="@Value"><xsl:value-of select="@Value"/></xsl:when><xsl:otherwise><xsl:value-of select="."/></xsl:otherwise></xsl:choose>')<xsl:text/>
  2283.                     </xsl:attribute>
  2284.                 </xz:variable>
  2285.             </xsl:otherwise>
  2286.         </xsl:choose>
  2287.     </xsl:template>
  2288.     
  2289.     <xsl:template mode="genTemplates" match="ScriptQuote">
  2290.         <xsl:param name="currentView"/>        
  2291.         <xsl:param name="fieldData"/>
  2292.         <xsl:param name="renderPattern"/>
  2293.         <xsl:param name="Field"/>
  2294.         
  2295.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  2296.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  2297.  
  2298.         <xsl:choose>  
  2299.             <!-- if we're inside a quote, that means we can't put <xsl:value-of> stuffs, instead we need to
  2300.                       use a variable, which fortunately has been defined by us.-->
  2301.             <xsl:when test="@NotAddingQuote='TRUE'">
  2302.                 <xsl:apply-templates mode="genTemplates" select="*">
  2303.                     <xsl:with-param name="currentView" select="$currentView"/>
  2304.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  2305.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2306.                 </xsl:apply-templates>
  2307.             </xsl:when>
  2308.             <!-- another possibility is <a href="httpvdir"...-->
  2309.             <xsl:when test="substring($prevStr, string-length($prevStr), 1) = ','">
  2310.                 <xsl:text/><xsl:text disable-output-escaping="yes">"</xsl:text><xsl:apply-templates mode="genTemplates" select="*">
  2311.                     <xsl:with-param name="currentView" select="$currentView"/>
  2312.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  2313.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2314.                 </xsl:apply-templates><xsl:text disable-output-escaping="yes">"</xsl:text><xsl:text/>
  2315.             </xsl:when>
  2316.             <xsl:when test="(name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = $singleQuote) or (ancestor::URLEncode)">
  2317.                 <xsl:apply-templates mode="genTemplates-inscript" select="*">
  2318.                     <xsl:with-param name="currentView" select="$currentView"/>
  2319.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  2320.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2321.                 </xsl:apply-templates>
  2322.             </xsl:when>
  2323.             <xsl:otherwise>
  2324.                 <xsl:apply-templates mode="genTemplates-inscript" select=".">
  2325.                     <xsl:with-param name="currentView" select="$currentView"/>
  2326.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  2327.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2328.                 </xsl:apply-templates>
  2329.             </xsl:otherwise>
  2330.         </xsl:choose>    
  2331.     </xsl:template>
  2332.     
  2333.     <!-- render field value based on field type.-->
  2334.     <xsl:template name="GetFieldValue">
  2335.         <xsl:param name="columnName"/>
  2336.         <xsl:param name="fieldData"/>
  2337.         
  2338.         <xsl:choose>
  2339.             <xsl:when test="$fieldData/@Type='DateTime'">
  2340.                 <xsl:choose>
  2341.                     <xsl:when test="$fieldData/@Format='DateOnly'">
  2342.                         <xsl:text/>ddwrt:FormatDate(string(@<xsl:value-of select="$columnName"/>),number($Language),1)<xsl:text/>        
  2343.                     </xsl:when>
  2344.                     <xsl:otherwise>
  2345.                         <xsl:text/>ddwrt:FormatDate(string(@<xsl:value-of select="$columnName"/>),number($Language),5)<xsl:text/>
  2346.                     </xsl:otherwise>
  2347.                 </xsl:choose>
  2348.             </xsl:when>
  2349.             <xsl:when test="$fieldData/@Type = 'Number' or ($fieldData/@Type='Calculated' and $fieldData/@ResultType = 'Number')">
  2350.                 <xsl:choose>
  2351.                     <xsl:when test="$fieldData/@Percentage='TRUE'">format-number(string(@<xsl:value-of select="$columnName"/>), '#,##0%;-#')</xsl:when>
  2352.                     <xsl:otherwise>format-number(string(@<xsl:value-of select="$columnName"/>), '#,##0.###;-#')</xsl:otherwise>
  2353.                 </xsl:choose>
  2354.             </xsl:when>
  2355.             <xsl:when test="$fieldData/@Type = 'Counter'">
  2356.                 <xsl:text/>format-number(string(@<xsl:value-of select="$columnName"/>), '#;-#')<xsl:text/>
  2357.             </xsl:when>
  2358.             <xsl:when test="$fieldData/@Type = 'URL'">
  2359.                 <xsl:text/>substring-before(@<xsl:value-of select="$columnName"/>, ', ')<xsl:text/>
  2360.             </xsl:when>
  2361.             <xsl:otherwise><xsl:text/>@<xsl:value-of select="$columnName"/><xsl:text/>
  2362.             </xsl:otherwise>
  2363.         </xsl:choose>    
  2364.     </xsl:template>
  2365.  
  2366.     <xsl:template mode="genTemplates" match="Column">
  2367.         <xsl:param name="currentView"/>        
  2368.         <xsl:param name="fieldData"/>
  2369.         <xsl:param name="renderPattern"/>        
  2370.         <xsl:param name="Field"/>
  2371.  
  2372.         <xsl:variable name="columnName">
  2373.             <xsl:choose>
  2374.                 <xsl:when test="@Name"><xsl:value-of select="@Name"/></xsl:when>
  2375.                 <xsl:otherwise><xsl:value-of select="$fieldData/@Name"/></xsl:otherwise>
  2376.             </xsl:choose>
  2377.         </xsl:variable>
  2378.  
  2379.         <xsl:variable name="currentField" select="/List/MetaData/Fields/Field[@Name=$columnName] | $fieldData[@Name=$columnName]"/>
  2380.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  2381.         <xsl:variable name="nextNode" select="following-sibling::*[1]"/>        
  2382.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  2383.         <xsl:variable name="nextStr"     select="normalize-space(string(following-sibling::*[1]))"/>
  2384.  
  2385.         <!-- if we don't have the column name, don't bother the @ows-->
  2386.         <xsl:choose>
  2387.         <xsl:when test="$codeReduced='1' and $currentField/@Type='User' and ancestor::ScriptQuote">{ddwrt:GetUserID('<xsl:value-of select="$columnName"/>')}</xsl:when>
  2388.         <xsl:when test="not ($columnName = '')">
  2389.             <xsl:choose>  
  2390.                 <xsl:when test="name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr)-2, 3) = 'ID='">{@ID}</xsl:when>
  2391.                 <!-- if we're inside a quote, that means we can't put <xsl:value-of> stuffs, instead we need to
  2392.                       use a variable, which fortunately has been defined by us.-->
  2393.                 <xsl:when test="(name($prevNode) = 'HTML' and 
  2394.                     (substring($prevStr, string-length($prevStr), 1) = '"' or (substring($prevStr, 1, 1) = '<' and not(substring($prevStr, string-length($prevStr), 1)='>')))) or
  2395.                     (name($nextNode) = 'HTML' and substring($nextStr, 1, 1) = '"')">
  2396.                     <xsl:text/>{<xsl:call-template name="GetFieldValue">
  2397.                         <xsl:with-param name="columnName" select="$columnName"/>
  2398.                         <xsl:with-param name="fieldData" select="$currentField"/>
  2399.                     </xsl:call-template>}<xsl:text/>
  2400.                 </xsl:when>
  2401.                 <!-- if we're preceded by a node that ends with '=', we're already defined this variable -->
  2402.                 <xsl:when test="name($prevNode) = 'HTML' and 
  2403.                     substring($prevStr, string-length($prevStr), 1) = '=' and not(substring($nextStr, 1, 1) = '"')">
  2404.                         <xz:value-of>
  2405.                             <xsl:attribute name="select">@ID</xsl:attribute>
  2406.                         </xz:value-of>
  2407.                 </xsl:when>
  2408.                 <!-- if we're preceded by a node that ends with ':', we're inside a "" node -->
  2409.                 <xsl:when test="name($prevNode) = 'HTML' and 
  2410.                     substring($prevStr, string-length($prevStr), 1) = ':'">{@ID}</xsl:when>
  2411.                     
  2412.                 <!-- if we're in the inline field, just output the name-->
  2413.                 <xsl:when test="@HTMLEncode='TRUE' and ancestor::*[Field] and (not(name($Field) = 'ViewBody') 
  2414.                                     and not(name($Field) = 'ListFormBody'))">
  2415.                     <xz:value-of>
  2416.                         <xsl:attribute name="select">
  2417.                             <xsl:text/>@<xsl:value-of select="$columnName"/><xsl:text/>
  2418.                         </xsl:attribute>
  2419.                     </xz:value-of>
  2420.                 </xsl:when>
  2421.                 
  2422.                 <!--if inside the script tag, we'll have to close the cdata section and reopen it afterwards. -->
  2423.                 <xsl:when test="ancestor::ScriptQuote">
  2424.                     <xsl:text/>{<xsl:call-template name="GetFieldValue">
  2425.                         <xsl:with-param name="columnName" select="$columnName"/>
  2426.                         <xsl:with-param name="fieldData" select="$currentField"/>
  2427.                     </xsl:call-template>}<xsl:text/>
  2428.                 </xsl:when>
  2429.                 <!-- inside expr (1,2), we're just evaluating the @ in a big <xsl:when >-->
  2430.                 <xsl:when test="ancestor::Expr or ancestor::Expr1 or ancestor::Expr2">
  2431.                     <xsl:call-template name="GetFieldValue">
  2432.                         <xsl:with-param name="columnName" select="$columnName"/>
  2433.                         <xsl:with-param name="fieldData" select="$currentField"/>
  2434.                     </xsl:call-template>
  2435.                 </xsl:when>
  2436.                 <xsl:when test="@HTMLEncode = 'TRUE'">
  2437.                     <xsl:choose>
  2438.                         <xsl:when test="$currentField/@Type= 'MultiChoice'">
  2439.                             <xz:call-template name="stringreplace">
  2440.                                 <xz:with-param name="stringvalue">
  2441.                                     <xz:choose>
  2442.                                         <xz:when>
  2443.                                             <xsl:attribute name="test">substring(@<xsl:value-of select="$columnName"/>, 1, 2)=';#'</xsl:attribute>
  2444.                                             <xz:value-of>
  2445.                                                 <xsl:attribute name="select">substring(@<xsl:value-of select="$columnName"/>, 3)</xsl:attribute>
  2446.                                             </xz:value-of>
  2447.                                         </xz:when>
  2448.                                         <xz:otherwise>
  2449.                                             <xz:value-of>
  2450.                                                 <xsl:attribute name="select">@<xsl:value-of select="$columnName"/></xsl:attribute>
  2451.                                             </xz:value-of>
  2452.                                         </xz:otherwise>
  2453.                                     </xz:choose>
  2454.                                 </xz:with-param>                                    
  2455.                                 <xz:with-param name="from">
  2456.                                     <xsl:attribute name="select">';#'</xsl:attribute>
  2457.                                 </xz:with-param>
  2458.                                 <xz:with-param name="to">
  2459.                                     <xsl:attribute name="select">';'</xsl:attribute>
  2460.                                 </xz:with-param>
  2461.                             </xz:call-template>
  2462.                         </xsl:when>
  2463.                         <xsl:otherwise>
  2464.                         <xz:value-of>
  2465.                             <xsl:attribute name="disable-output-escaping">
  2466.                                 <xsl:choose>
  2467.                                     <xsl:when test="@AutoNewLine='TRUE'">yes</xsl:when>
  2468.                                     <xsl:otherwise>no</xsl:otherwise>
  2469.                                 </xsl:choose>
  2470.                             </xsl:attribute>
  2471.                             <xsl:attribute name="select">
  2472.                                 <xsl:choose>
  2473.                                     <xsl:when test="$columnName = 'Modified' or $columnName = 'Created'">
  2474.                                         <xsl:text/>ddwrt:FormatDate(string(@<xsl:value-of select="$columnName"/>), number($Language), 5)<xsl:text/>
  2475.                                     </xsl:when>
  2476.                                     <xsl:when test="@AutoNewLine='TRUE'"><xsl:text/>ddwrt:AutoNewLine(string(@<xsl:value-of select="$columnName"/>))<xsl:text/></xsl:when>
  2477.                                     <xsl:otherwise>
  2478.                                         <xsl:call-template name="GetFieldValue">
  2479.                                             <xsl:with-param name="columnName" select="$columnName"/>
  2480.                                             <xsl:with-param name="fieldData" select="$currentField"/>
  2481.                                         </xsl:call-template>
  2482.                                     </xsl:otherwise>
  2483.                                 </xsl:choose>
  2484.                             </xsl:attribute>
  2485.                         </xz:value-of>
  2486.                         </xsl:otherwise>
  2487.                     </xsl:choose>
  2488.                 </xsl:when>
  2489.                 <xsl:when test="ancestor::Length">
  2490.                     <xsl:call-template name="GetFieldValue">
  2491.                         <xsl:with-param name="columnName" select="$columnName"/>
  2492.                         <xsl:with-param name="fieldData" select="$currentField"/>
  2493.                     </xsl:call-template>
  2494.                 </xsl:when>
  2495.                 <xsl:when test="(ancestor::Case or ancestor::Default) and not(substring($nextStr, 1, 1) = '"') or (name(ancestor::*[1]) = 'RenderPattern')">
  2496.                     <xsl:choose>
  2497.                         <xsl:when test="$currentField/@Type= 'MultiChoice'">
  2498.                             <xz:call-template name="stringreplace">
  2499.                                 <xz:with-param name="stringvalue">
  2500.                                     <xsl:attribute name="select">@<xsl:value-of select="$columnName"/></xsl:attribute>
  2501.                                 </xz:with-param>                                    
  2502.                                 <xz:with-param name="from">
  2503.                                     <xsl:attribute name="select">';#'</xsl:attribute>
  2504.                                 </xz:with-param>
  2505.                                 <xz:with-param name="to">
  2506.                                     <xsl:attribute name="select">';'</xsl:attribute>
  2507.                                 </xz:with-param>
  2508.                             </xz:call-template>
  2509.                         </xsl:when>
  2510.                         <xsl:otherwise>
  2511.                             <xsl:choose>
  2512.                                 <xsl:when test="$currentField/@Type='Note' and $currentField/@RichText='TRUE'">
  2513.                                     <xz:value-of>
  2514.                                         <xsl:attribute name="disable-output-escaping">yes</xsl:attribute>
  2515.                                         <xsl:attribute name="select">
  2516.                                             <xsl:call-template name="GetFieldValue">
  2517.                                                 <xsl:with-param name="columnName" select="$columnName"/>
  2518.                                                 <xsl:with-param name="fieldData" select="$currentField"/>
  2519.                                             </xsl:call-template>
  2520.                                         </xsl:attribute>
  2521.                                     </xz:value-of>                                        
  2522.                                 </xsl:when>
  2523.                                 <xsl:otherwise>
  2524.                                     <xsl:text/>{<xsl:call-template name="GetFieldValue">
  2525.                                         <xsl:with-param name="columnName" select="$columnName"/>
  2526.                                         <xsl:with-param name="fieldData" select="$currentField"/>
  2527.                                     </xsl:call-template>}<xsl:text/>
  2528.                                 </xsl:otherwise>
  2529.                             </xsl:choose>
  2530.                         </xsl:otherwise>
  2531.                     </xsl:choose>                                
  2532.                 </xsl:when>
  2533.                 <xsl:otherwise>
  2534.                     <xsl:choose>
  2535.                         <xsl:when test="$currentField/@Type='Note' and $currentField/@RichText='TRUE'">
  2536.                             <xz:value-of>
  2537.                                 <xsl:attribute name="disable-output-escaping">yes</xsl:attribute>
  2538.                                 <xsl:attribute name="select">
  2539.                                     <xsl:call-template name="GetFieldValue">
  2540.                                         <xsl:with-param name="columnName" select="$columnName"/>
  2541.                                         <xsl:with-param name="fieldData" select="$currentField"/>
  2542.                                     </xsl:call-template>
  2543.                                 </xsl:attribute>
  2544.                             </xz:value-of>                                        
  2545.                         </xsl:when>
  2546.                         <xsl:otherwise>
  2547.                             <xsl:text/>{<xsl:call-template name="GetFieldValue">
  2548.                                 <xsl:with-param name="columnName" select="$columnName"/>
  2549.                                 <xsl:with-param name="fieldData" select="$currentField"/>
  2550.                             </xsl:call-template>}<xsl:text/>
  2551.                         </xsl:otherwise>
  2552.                     </xsl:choose>                        
  2553.                 </xsl:otherwise>
  2554.             </xsl:choose>
  2555.         </xsl:when>
  2556.         </xsl:choose>
  2557.     </xsl:template>
  2558.  
  2559.     <xsl:template mode="genTemplates" match="Column2">
  2560.         <xsl:param name="currentView"/>        
  2561.         <xsl:param name="fieldData"/>
  2562.         <xsl:param name="renderPattern"/>        
  2563.         <xsl:param name="Field"/>
  2564.  
  2565.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  2566.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  2567.         <xsl:variable name="nextStr"     select="normalize-space(string(following-sibling::*[1]))"/>
  2568.  
  2569.         <!-- column2 means the descriptive text (Comments)-->
  2570.         <xsl:variable name="columnName">
  2571.             <xsl:choose>
  2572.                 <xsl:when test="@Name"><xsl:value-of select="@Name"/></xsl:when>
  2573.                 <xsl:otherwise><xsl:value-of select="$fieldData/@Name"/></xsl:otherwise>
  2574.             </xsl:choose>
  2575.         </xsl:variable>
  2576.         
  2577.         <xsl:choose>  <!-- if we're in the lookupRP field, just output the name-->
  2578.             <!-- if we're inside a quote, that means we can't put <xsl:value-of> stuffs, instead we need to
  2579.                   use a variable, which fortunately has been defined by us.-->
  2580.             <xsl:when test="name($prevNode) = 'HTML' and 
  2581.                 (substring($prevStr, string-length($prevStr), 1) = '"' or substring($nextStr, 1, 1) = '"')">
  2582.                 <xsl:text/>{substring-after(@<xsl:value-of select="$columnName"/>, ', ')}<xsl:text/>
  2583.             </xsl:when>
  2584.  
  2585.             <xsl:when test="@HTMLEncode='TRUE' and ancestor::*[Field] and (not(name($Field) = 'ViewBody')) and (not(name($Field) = 'ListFormBody'))">
  2586.                     <xsl:text/><xsl:value-of select="substring-after($columnName, ', ')"/><xsl:text/>
  2587.             </xsl:when>
  2588.             <xsl:when test="@HTMLEncode = 'TRUE' or ancestor::*[ScriptQuote]">
  2589.                  <xz:value-of>
  2590.                     <xsl:attribute name="select">
  2591.                         <xsl:text/>substring-after(@<xsl:value-of select="$columnName"/>, ', ')<xsl:text/>
  2592.                     </xsl:attribute>
  2593.                 </xz:value-of>
  2594.             </xsl:when>
  2595.             <xsl:otherwise>
  2596.                 <xsl:text/>substring-after(@<xsl:value-of select="$columnName"/>, ', ')<xsl:text/>
  2597.             </xsl:otherwise>
  2598.         </xsl:choose>
  2599.     </xsl:template>
  2600.  
  2601.     <xsl:template mode="genTemplates" match="InForm">
  2602.         <xsl:text/>'FALSE'<xsl:text/>
  2603.     </xsl:template>
  2604.  
  2605.     <xsl:template mode="genTemplates" match="LookupColumn">
  2606.         <xsl:param name="currentView"/>        
  2607.         <xsl:param name="fieldData"/>
  2608.         <xsl:param name="renderPattern"/>
  2609.         <xsl:param name="Field"/>
  2610.  
  2611.         <xsl:variable name="columnName">
  2612.             <xsl:choose>
  2613.                 <xsl:when test="@Name"><xsl:value-of select="@Name"/></xsl:when>
  2614.                 <xsl:when test="@ShowField"><xsl:value-of select="@ShowField"/></xsl:when>
  2615.                 <xsl:otherwise><xsl:value-of select="$fieldData/@Name"/></xsl:otherwise>
  2616.             </xsl:choose>
  2617.         </xsl:variable>
  2618.         <xsl:variable name="prevStr" select="normalize-space(string(preceding-sibling::*[1]))"/>
  2619.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>
  2620.         <xsl:variable name="nextNode" select="following-sibling::*[1]"/>        
  2621.         <xsl:variable name="nextStr" select="normalize-space(string(following-sibling::*[1]))"/>
  2622.         
  2623.         <xsl:variable name="fieldData2" select="$fieldData[name()='Field'] | /List/MetaData/Fields/Field[@Name=current()/@Name]"/>
  2624.         
  2625.         <!-- if we don't have the column name, don't bother the @ows-->
  2626.         <xsl:choose>
  2627.         <xsl:when test="not ($columnName = '')">
  2628.             <xsl:choose>  <!-- if we're in the inline field, just output the name-->
  2629.                 <xsl:when test="@HTMLEncode='TRUE' and ancestor::*[Field] and (not(name($Field) = 'ViewBody')) and (not(name($Field) = 'ListFormBody'))">
  2630.                     <xz:value-of>
  2631.                         <xsl:if test="$fieldData2/@Type='User' and $codeReduced='1'"><xsl:attribute name="disable-output-escaping">yes</xsl:attribute></xsl:if>
  2632.                         <xsl:attribute name="select">
  2633.                             <xsl:text/>@<xsl:value-of select="$columnName"/><xsl:text/>
  2634.                         </xsl:attribute>
  2635.                     </xz:value-of>
  2636.                 </xsl:when>
  2637.                 <!-- another heuristic: notaddingquote is set, then it should be just @..
  2638.                 also anything really inside default or case tag should be enclosed with <value-of>>-->
  2639.                 <xsl:when test="ancestor::ScriptQuote[@NotAddingQuote]">
  2640.                     <xsl:choose>
  2641.                         <xsl:when test="@ShowField='EMail'">
  2642.                             <xsl:text/>{ddwrt:UserLookup(string(@<xsl:value-of select="$fieldData/@Name"/>), string($EMail))}<xsl:text/>
  2643.                         </xsl:when>
  2644.                         <xsl:when test="@ShowField">
  2645.                             <!--<xsl:text/>{ddwrt:UserLookup("@ID", "<xsl:value-of select="@ShowField"/>")}<xsl:text/>-->
  2646.                             <xsl:text/>{$UserLookup<xsl:value-of select="generate-id($fieldData)"/><xsl:value-of select="generate-id(.)"/>}<xsl:text/>
  2647.                         </xsl:when>
  2648.                         <xsl:otherwise>
  2649.                             <xsl:text/>{@<xsl:value-of select="$columnName"/>}<xsl:text/>
  2650.                         </xsl:otherwise>
  2651.                     </xsl:choose>    
  2652.                 </xsl:when>
  2653.                 <!-- if it's after / (fieldref), or ".."-->
  2654.                 <xsl:when test="name($prevNode) = 'HTML' and (substring($prevStr, string-length($prevStr), 1) = '/' or substring($prevStr, 1, 1) = '/' or substring($prevStr, string-length($prevStr), 1) = '"')">
  2655.                     <xsl:text/>{@<xsl:value-of select="$columnName"/>}<xsl:text/>
  2656.                 </xsl:when>
  2657.                 <xsl:when test="name($nextNode) = 'HTML' and substring($nextStr, 1, 1) = '"'">
  2658.                     <xsl:text/>{@<xsl:value-of select="$columnName"/>}<xsl:text/>
  2659.                 </xsl:when>
  2660.                 <xsl:when test="@ShowField">
  2661.                     <xsl:text/>ddwrt:UserLookup(string(@<xsl:value-of select='$fieldData/@Name'/>), "<xsl:value-of select='@ShowField'/>")<xsl:text/>
  2662.                 </xsl:when>                
  2663.                 <xsl:when test="(@HTMLEncode = 'TRUE' and not(ancestor::RenderPattern)) or 
  2664.                             (ancestor::ScriptQuote[not (@NotAddingQuote)]) or
  2665.                             ((ancestor::Default or ancestor::Case) and not(ancestor::Expr or ancestor::Expr1 or ancestor::Expr2))">
  2666.                     <xz:value-of>
  2667.                         <xsl:if test="$fieldData2/@Type='User' and $codeReduced='1'"><xsl:attribute name="disable-output-escaping">yes</xsl:attribute></xsl:if>
  2668.                         <xsl:attribute name="select">
  2669.                             <xsl:choose>
  2670.                                 <!-- for some internal readonly fields, we have special handling -->
  2671.                                 <xsl:when test="$fieldData2/@Type='Lookup' and $fieldData2/@List='Docs' and ($columnName='Last_x0020_Modified' or $columnName='Created_x0020_Date')">ddwrt:FormatDate(string(@<xsl:value-of select="$columnName"/>),number($Language),5)</xsl:when>
  2672.                                 <xsl:when test="$fieldData2/@Type='Lookup' and $fieldData2/@List='Docs' and $columnName='File_x0020_Size'">floor(number(@<xsl:value-of select="$columnName"/>) div 1024) + 1</xsl:when>
  2673.                                 <xsl:otherwise>
  2674.                                     <xsl:text/>@<xsl:value-of select="$columnName"/><xsl:text/>
  2675.                                 </xsl:otherwise>
  2676.                             </xsl:choose>
  2677.                         </xsl:attribute>
  2678.                     </xz:value-of>
  2679.                 </xsl:when>
  2680.                 <!-- if we're inside a form, we'll do the lookup-->
  2681.                 <xsl:when test="$isAViewAndNotAForm = '0' and ancestor::ScriptQuote">
  2682.                     <xz:value-of>
  2683.                         <xsl:attribute name="select">
  2684.                             <xsl:text/>/dsQueryResponse/<xsl:value-of select="$resultRoot"/>/<xsl:value-of select="$resultRow"/>[@ID = $ID]/@<xsl:value-of select="$columnName"/><xsl:text/>
  2685.                         </xsl:attribute>
  2686.                     </xz:value-of>
  2687.                 </xsl:when>
  2688.                 <xsl:otherwise>
  2689.                     <xsl:text/>@<xsl:value-of select="$columnName"/><xsl:text/>
  2690.                 </xsl:otherwise>
  2691.             </xsl:choose>
  2692.         </xsl:when>
  2693.         </xsl:choose>
  2694.     </xsl:template>
  2695.     
  2696.  
  2697.     <xsl:template mode="genTemplates" match="FieldFilterOptions">
  2698.         <xsl:param name="currentView"/>        
  2699.         <xsl:param name="fieldData"/>
  2700.         <xsl:param name="renderPattern"/>
  2701.         <xsl:param name="Field"/>
  2702.         
  2703.         <xsl:variable name="FilterOptionsListName">
  2704.             <xsl:choose>
  2705.                 <xsl:when test="$Field">optionsList<xsl:value-of select="generate-id($Field)"/></xsl:when>
  2706.                 <xsl:otherwise>optionsList<xsl:value-of select="generate-id($Field)"/></xsl:otherwise>
  2707.             </xsl:choose>
  2708.         </xsl:variable>        
  2709.  
  2710.         <xz:variable>
  2711.             <xsl:attribute name="name"><xsl:value-of select="$FilterOptionsListName"/></xsl:attribute>
  2712.             <xsl:attribute name="select">ddwrt:FieldFilterOptions('<xsl:value-of select="$fieldData/@Name"/>')</xsl:attribute>
  2713.         </xz:variable>
  2714.         <xz:for-each>
  2715.             <!-- todo: intentionally leave out the $ below since the run time is not ready yet -->
  2716.             <xsl:attribute name="select">$<xsl:value-of select="$FilterOptionsListName"/></xsl:attribute>
  2717.             <option>
  2718.                 <xz:attribute name="value"><xz:value-of select="@value"/></xz:attribute>
  2719.                 <xz:value-of select="@display"/>
  2720.             </option>
  2721.         </xz:for-each>    
  2722.     </xsl:template>
  2723.     
  2724.     <xsl:template mode="genTemplates" match="URLEncode">
  2725.     <xsl:param name="currentView"/>
  2726.         <!-- concat the url to be encoded, unless it has only one child-->
  2727.         <xz:variable>
  2728.             <xsl:attribute name="name">URLStr<xsl:value-of select="generate-id($currentView)"/></xsl:attribute>
  2729.             <xsl:choose>
  2730.                 <xsl:when test="last() = 1">
  2731.                     <xsl:apply-templates mode="genTemplates" select="*"/>
  2732.                 </xsl:when>
  2733.                 <xsl:otherwise>
  2734.                     <xsl:attribute name="select">
  2735.                         <xsl:text/>concat(<xsl:for-each select="*"><xsl:apply-templates mode="genTemplates" select="."/><xsl:if test="not(position() = last())">,</xsl:if></xsl:for-each>)<xsl:text/>
  2736.                     </xsl:attribute>
  2737.                 </xsl:otherwise>
  2738.             </xsl:choose>    
  2739.         </xz:variable>
  2740.         
  2741.         <xsl:variable name="name">URLStr<xsl:value-of select="generate-id($currentView)"/></xsl:variable>
  2742.         <xz:value-of>
  2743.             <xsl:attribute name="select">
  2744.                 <xsl:text/>ddwrt:URLEncode('$<xsl:value-of select="$name"/>')<xsl:text/>
  2745.             </xsl:attribute>
  2746.         </xz:value-of>
  2747.     </xsl:template>
  2748.     
  2749.     <xsl:template mode="genVariables" match="Limit">
  2750.         <xsl:param name="currentView"/>        
  2751.  
  2752.         <xz:variable>
  2753.             <xsl:attribute name="name">LimitStr<xsl:value-of select="generate-id($currentView)"/></xsl:attribute>
  2754.             <xsl:attribute name="select">
  2755.                 <xsl:text/>concat(<xsl:for-each select="*">
  2756.                             <xsl:apply-templates mode="genTemplates" select="."/><xsl:if test="not(position() = last())">,</xsl:if>
  2757.                             </xsl:for-each>)<xsl:text/>
  2758.             </xsl:attribute>
  2759.         </xz:variable>
  2760.         
  2761.     </xsl:template>
  2762.     
  2763.     <xsl:template mode="genTemplates" match="Limit">
  2764.         <xsl:param name="currentView"/>        
  2765.         <xsl:param name="fieldData"/>
  2766.         <xsl:param name="renderPattern"/>
  2767.         <xsl:param name="Field"/>
  2768.  
  2769.         <!--concat all the strings inside the <limit> tag -->
  2770.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  2771.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  2772.  
  2773.         <xsl:variable name="columnName" select="Column/@Name"/>
  2774.         <xsl:variable name="currentField" select="/List/MetaData/Fields/Field[@Name=$columnName] | $fieldData[@Name=$columnName]"/>
  2775.  
  2776.         <!--params-->
  2777.         <xsl:variable name="AutoHyperLink">
  2778.             <xsl:choose>
  2779.                 <xsl:when test="@AutoHyperLink"><xsl:value-of select="@AutoHyperLink"/></xsl:when>
  2780.                 <xsl:otherwise>TRUE</xsl:otherwise>
  2781.             </xsl:choose>
  2782.         </xsl:variable>
  2783.         <xsl:variable name="AutoNewLine">
  2784.             <xsl:choose>
  2785.                 <xsl:when test="@AutoNewLine"><xsl:value-of select="@AutoNewLine"/></xsl:when>
  2786.                 <xsl:otherwise>TRUE</xsl:otherwise>
  2787.             </xsl:choose>
  2788.         </xsl:variable>
  2789.         <xsl:variable name="HTMLEncode">
  2790.             <xsl:choose>
  2791.                 <xsl:when test="@HTMLEncode"><xsl:value-of select="@HTMLEncode"/></xsl:when>
  2792.                 <xsl:otherwise>TRUE</xsl:otherwise>
  2793.             </xsl:choose>
  2794.         </xsl:variable>
  2795.         <xsl:variable name="Len">
  2796.             <xsl:choose>
  2797.                 <xsl:when test="@Len"><xsl:value-of select="@Len"/></xsl:when>
  2798.                 <xsl:otherwise>128</xsl:otherwise>
  2799.             </xsl:choose>
  2800.         </xsl:variable>
  2801.         <xsl:variable name="MoreText">
  2802.             <xsl:choose>
  2803.                 <xsl:when test="@MoreText"><xsl:value-of select="@MoreText"/></xsl:when>
  2804.                 <xsl:otherwise>NULL</xsl:otherwise>
  2805.             </xsl:choose>
  2806.         </xsl:variable>
  2807.         <xsl:variable name="StripWS">
  2808.             <xsl:choose>
  2809.                 <xsl:when test="@StripWS"><xsl:value-of select="@StripWS"/></xsl:when>
  2810.                 <xsl:otherwise>TRUE</xsl:otherwise>
  2811.             </xsl:choose>
  2812.         </xsl:variable>
  2813.  
  2814.         <!--if the previous node is an html node that ends with ", we'll do {ddwrt:} directly.
  2815.               by default, len is 128 and moreText is ... -->                
  2816.         <xsl:choose>
  2817.             <xsl:when test="name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = '"'">
  2818.                 <xsl:text/>{ddwrt:Limit($LimitStr<xsl:value-of select="generate-id($Field)"/>, '<xsl:value-of select="$Len"/>', '<xsl:value-of select="$MoreText"/>')}<xsl:text/>
  2819.             </xsl:when>
  2820.             <xsl:when test="ancestor::Fields and not(ancestor::Field)">
  2821.                 <xz:variable>
  2822.                     <xsl:attribute name="name">LimitStr<xsl:value-of select="generate-id($Field)"/></xsl:attribute>
  2823.                     <xsl:apply-templates mode="genTemplates" select="*">
  2824.                         <xsl:with-param name="currentView" select="$currentView"/>
  2825.                         <xsl:with-param name="fieldData" select="$fieldData"/>
  2826.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2827.                         <xsl:with-param name="Field" select="$Field"/>
  2828.                     </xsl:apply-templates>    
  2829.                 </xz:variable>
  2830.                 <xz:value-of>
  2831.                     <xsl:attribute name="select">
  2832.                         <xsl:text/>ddwrt:Limit($LimitStr<xsl:value-of select="generate-id($Field)"/>, '<xsl:value-of select="$Len"/>', '<xsl:value-of select="$MoreText"/>')<xsl:text/>
  2833.                     </xsl:attribute>
  2834.                 </xz:value-of>
  2835.             </xsl:when>
  2836.             <xsl:when test=".//GetVar">
  2837.                 <xsl:choose>
  2838.                     <xsl:when test="GetVar">
  2839.                         <xz:value-of>
  2840.                             <xsl:attribute name="select">
  2841.                                 <xsl:text/>ddwrt:Limit(ddwrt:GetVar('<xsl:value-of select="GetVar/@Name"/>'), '<xsl:value-of select="$Len"/>', '...')<xsl:text/>    
  2842.                             </xsl:attribute>
  2843.                         </xz:value-of>
  2844.                     </xsl:when>
  2845.                     <xsl:otherwise>
  2846.                         <xz:variable>
  2847.                             <xsl:attribute name="name">LimitStr<xsl:value-of select="generate-id(.)"/></xsl:attribute>
  2848.                             <xsl:apply-templates mode="genTemplates" select="*">
  2849.                                 <xsl:with-param name="currentView" select="$currentView"/>
  2850.                                 <xsl:with-param name="fieldData" select="$fieldData"/>
  2851.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  2852.                                 <xsl:with-param name="Field" select="$Field"/>
  2853.                             </xsl:apply-templates>    
  2854.                         </xz:variable>
  2855.                         <xz:value-of>
  2856.                             <xsl:attribute name="select">
  2857.                                 <xsl:text/>ddwrt:Limit($LimitStr<xsl:value-of select="generate-id(.)"/>, '<xsl:value-of select="$Len"/>', '<xsl:value-of select="$MoreText"/>')<xsl:text/>
  2858.                             </xsl:attribute>
  2859.                         </xz:value-of>
  2860.                     </xsl:otherwise>
  2861.                 </xsl:choose>
  2862.             </xsl:when>
  2863.             <xsl:otherwise>
  2864.                 <xz:value-of>
  2865.                     <xsl:attribute name="disable-output-escaping">
  2866.                         <xsl:choose>
  2867.                             <xsl:when test="$currentField/@Type='Note' and $currentField/@RichText='TRUE'">yes</xsl:when>
  2868.                             <xsl:otherwise>no</xsl:otherwise>
  2869.                         </xsl:choose>
  2870.                     </xsl:attribute>
  2871.                     <xsl:attribute name="select">ddwrt:Limit(string(@<xsl:value-of select="Column/@Name"/>), <xsl:value-of select="$Len"/>, '...')</xsl:attribute>
  2872.                 </xz:value-of>
  2873.             </xsl:otherwise>
  2874.         </xsl:choose>
  2875.     </xsl:template>
  2876.     
  2877.     <xsl:template mode="genTemplates" match="SelectOptions">
  2878.         <xsl:param name="currentView"/>        
  2879.         <xsl:param name="fieldData"/>
  2880.         <xsl:param name="renderPattern"/>
  2881.         <xsl:param name="Field"/>
  2882.         <xsl:param name="ThisField"/>
  2883.             
  2884.         <xsl:variable name="optionsListName">FilterOptionsList<xsl:value-of select="$fieldData/@Name"/></xsl:variable>
  2885.         
  2886.         <xz:variable>
  2887.             <xsl:attribute name="name"><xsl:value-of select="$optionsListName"/></xsl:attribute>
  2888.             <xsl:attribute name="select">ddwrt:GetFieldOptions('<xsl:value-of select="$fieldData/@Name"/>')</xsl:attribute>
  2889.         </xz:variable>
  2890.         <xz:for-each>
  2891.             <!-- todo: intentionally leave out the $ below since the run time is not ready yet -->
  2892.             <xsl:attribute name="select">$<xsl:value-of select="$optionsListName"/></xsl:attribute>
  2893.             <option>
  2894.                 <xz:attribute name="value"><xz:value-of select="@value"/></xz:attribute>
  2895.                 <xz:value-of select="@display"/>
  2896.             </option>
  2897.         </xz:for-each>
  2898.     </xsl:template>
  2899.  
  2900.     <xsl:template mode="genTemplates" match="Property">
  2901.         <xsl:param name="currentView"/>        
  2902.         <xsl:param name="fieldData"/>
  2903.         <xsl:param name="renderPattern"/>
  2904.         <xsl:param name="Field"/>
  2905.         
  2906.         <xsl:variable name="propertyNode" select="."/>
  2907.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  2908.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  2909.         <xsl:choose>
  2910.             <!-- if we have fielddata, then we resolve that way -->
  2911.             <xsl:when test="$fieldData and $fieldData/@*[name() = $propertyNode/@Select]">
  2912.                 <xsl:choose>
  2913.                     <!-- a heuristic : gleaning of sample caml yields the 
  2914.                         observation that if the htmlencode attribute is set to true, 
  2915.                         we are looking at something outside of a tag, otherwise
  2916.                         part of an attribute value -->
  2917.                     <xsl:when test="@HTMLEncode = 'TRUE'">
  2918.                         <xsl:value-of disable-output-escaping="yes" select="ddwrt:AutoNewLine(string($fieldData/@*[name() = $propertyNode/@Select]))"/>
  2919.                     </xsl:when>
  2920.                     <xsl:when test="(name(ancestor::*[1])='Expr' or name(ancestor::*[1])='Expr1' or name(ancestor::*[1])='Expr2') and count(ancestor::*[1]/*) = 1"> <!--just need the field name text -->
  2921.                         <xsl:text/>'<xsl:value-of select="$fieldData/@*[name() = $propertyNode/@Select]"/>'<xsl:text/>
  2922.                     </xsl:when>
  2923.                     <xsl:otherwise>
  2924.                             <xsl:text/><xsl:value-of select="$fieldData/@*[name() = $propertyNode/@Select]"/><xsl:text/>
  2925.                     </xsl:otherwise>
  2926.                 </xsl:choose>
  2927.             </xsl:when>
  2928.             <!-- otherwise we resolve with the ddwrt:ListProperty -->
  2929.             <xsl:otherwise>
  2930.                 <xsl:choose>
  2931.                     <!-- a heuristic : gleaning of sample caml yields the 
  2932.                         observation that if the htmlencode attribute is set to true, 
  2933.                         we are looking at something outside of a tag, otherwise
  2934.                         part of an attribute value -->
  2935.                     <xsl:when test="@HTMLEncode = 'TRUE' and not(name($prevNode) = 'HTML' and
  2936.                     (substring($prevStr, string-length($prevStr), 1) = '"' or
  2937.                     substring($prevStr, string-length($prevStr), 1) = $singleQuote))">
  2938.                         <xz:value-of>
  2939.                             <xsl:attribute name="select">
  2940.                                 <xsl:text/>ddwrt:ListProperty('<xsl:value-of select="@Select"/>')<xsl:text/>
  2941.                             </xsl:attribute>
  2942.                         </xz:value-of>
  2943.                     </xsl:when>
  2944.                     <!-- here we have a property that actually lives inside a <script> tag!-->
  2945.                     <xsl:when test="(ancestor::*[name()='FieldType' or name()='Row'][Field[@Name = 'TypeName'] = 'Text'] and ancestor::RenderPattern[@Name= 'NewPattern']) or (ancestor::FieldType[Field[@Name = 'TypeName'] = 'URL'] and ancestor::RenderPattern[@Name= 'NewPattern' or @Name = 'EditPattern'])">
  2946.                         <xz:value-of>
  2947.                             <xsl:attribute name="select">
  2948.                                 <xsl:text/>ddwrt:ListProperty('<xsl:value-of select="@Select"/>')<xsl:text/>
  2949.                             </xsl:attribute>
  2950.                         </xz:value-of>    
  2951.                     </xsl:when>
  2952.                     <xsl:when test="ancestor::Expr or ancestor::Expr1 or ancestor::Expr2">
  2953.                             <xsl:text/>ddwrt:GetVar('<xsl:value-of select="@Select"/>')<xsl:text/>
  2954.                     </xsl:when>
  2955.                     <xsl:otherwise>
  2956.                         <xsl:text/>{ddwrt:GetVar('<xsl:value-of select="@Select"/>')}<xsl:text/>
  2957.                     </xsl:otherwise>
  2958.                 </xsl:choose>
  2959.             </xsl:otherwise>
  2960.         </xsl:choose>
  2961.     </xsl:template>
  2962.  
  2963.     <xsl:template mode="genTemplates" match="IsPrivilegedUser">
  2964.         <xsl:param name="currentView"/>        
  2965.         <xsl:param name="fieldData"/>
  2966.         <xsl:param name="renderPattern"/>
  2967.         <xsl:param name="Field"/>
  2968.  
  2969.         <xsl:text/>ddwrt:IsPrivilegedUser()<xsl:text/>
  2970.     </xsl:template>
  2971.  
  2972.     <xsl:template mode="genTemplates" match="ListUrlDir">
  2973.         <xsl:param name="currentView"/>        
  2974.         <xsl:param name="fieldData"/>
  2975.         <xsl:param name="renderPattern"/>
  2976.         <xsl:param name="Field"/>
  2977.         
  2978.         <xsl:choose>
  2979.             <!-- a heuristic : gleaning of sample caml yields the 
  2980.                 observation that if the htmlencode attribute is set to true, 
  2981.                 we are looking at something outside of a tag, otherwise
  2982.                 part of an attribute value -->
  2983.  
  2984.             <xsl:when test="@WebRel">
  2985.                 <xsl:choose>
  2986.                     <xsl:when test="@HTMLEncode = 'TRUE' or ancestor::ListFormOpening">
  2987.                         <xz:value-of>
  2988.                             <xsl:attribute name="select">
  2989.                                 <xsl:text/>$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="@WebRel"/><xsl:text/>
  2990.                             </xsl:attribute>
  2991.                         </xz:value-of>
  2992.                     </xsl:when>
  2993.                     <xsl:otherwise>
  2994.                         <xsl:text/>{$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="@WebRel"/>}<xsl:text/>
  2995.                     </xsl:otherwise>
  2996.                 </xsl:choose>
  2997.             </xsl:when>
  2998.             <xsl:otherwise>
  2999.                 <xsl:choose>
  3000.                 <xsl:when test="ancestor::Expr or ancestor::Expr1 or ancestor::Expr2 or ancestor::SetVar">
  3001.                     <xsl:text/>$<xsl:value-of select="name(.)" disable-output-escaping="yes"/><xsl:text/>
  3002.                 </xsl:when>
  3003.                 <xsl:otherwise>
  3004.                     <xsl:text/>{$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>}<xsl:text/>
  3005.                 </xsl:otherwise>
  3006.                 </xsl:choose>
  3007.             </xsl:otherwise>
  3008.         </xsl:choose>
  3009.     </xsl:template>
  3010.  
  3011.     <xsl:template mode="genTemplates" match="URL">
  3012.         <xsl:param name="currentView"/>        
  3013.         <xsl:param name="fieldData"/>
  3014.         <xsl:param name="renderPattern"/>
  3015.         <xsl:param name="Field"/>
  3016.         
  3017.             <xsl:choose>
  3018.             <!-- a heuristic : gleaning of sample caml yields the 
  3019.                 observation that if the htmlencode attribute is set to true, 
  3020.                 we are looking at something outside of a tag, otherwise
  3021.                 part of an attribute value -->
  3022.             <xsl:when test="@HTMLEncode = 'TRUE'">
  3023.                 <xz:value-of>
  3024.                     <xsl:attribute name="select">
  3025.                         <xsl:text/>concat($PageUrl, '?ID=', @ID)<xsl:text/>
  3026.                     </xsl:attribute>
  3027.                 </xz:value-of>
  3028.             </xsl:when>
  3029.             <xsl:when test="not(@Cmd) or ancestor::DisplayPattern or ancestor::DisplayBidiPattern">
  3030.                 <xsl:choose>
  3031.                     <xsl:when test="@Cmd = 'Edit'">{$URL_Edit}?ID={@ID}</xsl:when>
  3032.                     <xsl:when test="@Cmd = 'New'">{$URL_New}?ID={@ID}</xsl:when>
  3033.                     <!--if we're inside display field, should display the item url instead of the page url. -->
  3034.                     <xsl:when test="ancestor::Field or not(@Cmd)">{$URL_Display}?ID={@ID}</xsl:when>
  3035.                     <xsl:otherwise>{$PageUrl}?ID={@ID}</xsl:otherwise>
  3036.                 </xsl:choose>
  3037.             </xsl:when>
  3038.             <xsl:when test="@Cmd='Lookup'">
  3039.                 <xsl:text/>{ddwrt:URLLookup('<xsl:value-of select="$fieldData/@List"/>', '<xsl:value-of select="$fieldData/@Name"/>', string(@ID))}<xsl:text/>
  3040.             </xsl:when>
  3041.             <xsl:otherwise>
  3042.                 <!-- new just return the url, otherwise add the id=? stuffs-->
  3043.                 <xsl:choose>
  3044.                     <xsl:when test="@Cmd = 'New' or @Cmd='Lookup'">            
  3045.                         <xsl:text/>{$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="@Cmd"/>}<xsl:text/>
  3046.                     </xsl:when>
  3047.                     <xsl:otherwise>
  3048.                         <xsl:text/>{$<xsl:value-of select="name(.)" disable-output-escaping="yes"/>_<xsl:value-of select="@Cmd"/>}?ID={@ID}<xsl:text/>
  3049.                     </xsl:otherwise>
  3050.                 </xsl:choose>
  3051.             </xsl:otherwise>
  3052.         </xsl:choose>
  3053.     </xsl:template>
  3054.  
  3055.     <xsl:template mode="genTemplates" match="GetVar">
  3056.         <xsl:param name="currentView"/>        
  3057.         <xsl:param name="fieldData"/>
  3058.         <xsl:param name="renderPattern"/>
  3059.         <xsl:param name="Field"/>
  3060.  
  3061.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  3062.         <xsl:variable name="origPrevStr" select="string(preceding-sibling::*[1])"/>
  3063.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  3064.         <xsl:variable name="nextStr"     select="normalize-space(string(following-sibling::*[1]))"/>
  3065.  
  3066.         <xsl:choose>
  3067.             <!-- a heuristic : gleaning of sample caml yields the 
  3068.                 observation that if the htmlencode attribute is set to true, 
  3069.                 we are looking at something outside of a tag, otherwise
  3070.                 part of an attribute value -->
  3071.             <xsl:when test="name($prevNode)='HTML' and substring($prevStr, string-length($prevStr), 1)='=' and @Name='NumColumns'">
  3072.                 <xsl:value-of select="count($currentView/ViewFields/FieldRef)"/>
  3073.             </xsl:when>
  3074.             <xsl:when test="ancestor::UrlBaseName">
  3075.                 <xsl:text/>ddwrt:GetVar('<xsl:value-of select="@Name"/>')<xsl:text/>
  3076.             </xsl:when>
  3077.             <xsl:when test="@Name='WPQ'">WPQ1</xsl:when>            
  3078.             <xsl:when test="@HTMLEncode = 'TRUE' and not(name($prevNode) = 'HTML' and 
  3079.                     (substring($prevStr, string-length($prevStr), 1) = '"' or
  3080.                     substring($prevStr, string-length($prevStr), 1) = $singleQuote)) ">
  3081.                 <xz:value-of>
  3082.                     <xsl:attribute name="select">ddwrt:GetVar('<xsl:value-of select="@Name"/>')</xsl:attribute>
  3083.                 </xz:value-of>
  3084.             </xsl:when>
  3085.             <!-- if we're inside a <script>-->
  3086.             <xsl:when test="substring($prevStr, 1, 1)=';' or substring($prevStr, 1, 1) = ':' or substring($prevStr, string-length($prevStr), 1) = ';' or 
  3087.                             substring($nextStr, 1, 1) = ';' or contains($prevStr, '<SCRIPT>') or contains($prevStr, '{') or (substring($nextStr, 1, 12) = 'upOneLevel()' and not(substring($nextStr, 13, 1)=';'))
  3088.                             or substring($origPrevStr, string-length($origPrevStr), 1) = ' '">
  3089.                 <xz:value-of>
  3090.                     <xsl:attribute name="select">ddwrt:GetVar('<xsl:value-of select="@Name"/>')</xsl:attribute>
  3091.                 </xz:value-of>                
  3092.             </xsl:when>
  3093.             <!-- if the var is inside listformopening node, it means it's probably
  3094.                 inside script, except that we're passed </script>, which means the node is preceded
  3095.                 by some <form or <input tag.
  3096.                 also if it's inside switch, we'll do the normal thing for it.-->    
  3097.             <xsl:when test="ancestor::ListFormOpening and not(substring-after($prevStr, '<Form')
  3098.                     or substring-after($prevStr, '<INPUT')) and not(ancestor::Switch)">
  3099.                 <xz:value-of>
  3100.                     <xsl:attribute name="select">ddwrt:GetVar('<xsl:value-of select="@Name"/>')</xsl:attribute>
  3101.                 </xz:value-of>                    
  3102.             </xsl:when>
  3103.  
  3104.             <!-- if we're inside the ifEqual, we're just variables inside the a=b pattern-->
  3105.             <xsl:when test="ancestor::IfEqual and (ancestor::Expr1 or ancestor::Expr2)">
  3106.                 <xsl:text/><xsl:choose>
  3107.                     <xsl:when test="@Name='Threaded'"><xsl:choose><xsl:when test="$isThreaded='TRUE'">'TRUE'</xsl:when><xsl:otherwise>'FALSE'</xsl:otherwise></xsl:choose></xsl:when>
  3108.                     <xsl:otherwise>ddwrt:GetVar('<xsl:value-of select="@Name"/>')</xsl:otherwise>
  3109.                 </xsl:choose><xsl:text/>                
  3110.             </xsl:when>
  3111.             <xsl:when test="ancestor::Limit or ancestor::Expr or ancestor::Expr1 or ancestor::Expr2">
  3112.                 <xsl:choose>
  3113.                     <xsl:when test="@Name='SortDisable'">'TRUE'</xsl:when> <!-- todo: add in the schema sortable info-->
  3114.                     <xsl:when test="@Name='Threaded'"><xsl:choose><xsl:when test="$isThreaded='TRUE'">'TRUE'</xsl:when><xsl:otherwise>'FALSE'</xsl:otherwise></xsl:choose></xsl:when>
  3115.                     <xsl:when test="@Name='FreeForm'"><xsl:choose><xsl:when test="$FreeForm='1'">'TRUE'</xsl:when><xsl:otherwise>''</xsl:otherwise></xsl:choose></xsl:when>
  3116.                     <xsl:otherwise>ddwrt:GetVar('<xsl:value-of select="@Name"/>')</xsl:otherwise>
  3117.                 </xsl:choose>
  3118.             </xsl:when>
  3119.             <xsl:when test="@Name='View'">
  3120.                 <xsl:text/>{$View}<xsl:text/>
  3121.             </xsl:when>
  3122.             <xsl:when test="ancestor::SetVar">
  3123.                 <xsl:text/>ddwrt:GetVar('<xsl:value-of select="@Name"/>')<xsl:text/>
  3124.             </xsl:when>
  3125.             <xsl:otherwise>
  3126.             <xsl:text/>{ddwrt:GetVar(<xsl:text disable-output-escaping="yes">&apos;</xsl:text><xsl:value-of select="@Name"/><xsl:text disable-output-escaping="yes">&apos;</xsl:text>)}<xsl:text/>
  3127.             </xsl:otherwise>
  3128.         </xsl:choose>
  3129.     </xsl:template>
  3130.         
  3131.     <xsl:template name="FieldExpandTempl" mode="genTemplates" match="Field[not (@*)]">
  3132.         <xsl:param name="currentView"/>        
  3133.         <xsl:param name="fieldData"/>
  3134.         <xsl:param name="renderPattern"/>
  3135.         <xsl:param name="Field"/>
  3136.         
  3137.         <xsl:variable name="fieldData2" select="$fieldData[name()='Field'] | /List/MetaData/Fields/Field[@Name=current()/@Name]"/>
  3138.         <xsl:variable name="inlineRP" select="$fieldData2/DisplayPattern"/>
  3139.         <xsl:variable name="lookupRP" select="($fldTypes/FieldTypes/FieldType | $fldTypes/List/Data/Rows/Row)[Field[@Name = 'TypeName'] = $fieldData2/@Type]/RenderPattern[@Name = $renderPattern]"/>
  3140.  
  3141.         <!-- need to find the appropriate render pattern and run it -->
  3142.         <xsl:choose>
  3143.             <xsl:when test="ancestor::Expr or ancestor::Expr1 or ancestor::Expr2 or ancestor::SetVar">
  3144.                 <xsl:text/>@<xsl:value-of select="$fieldData2/@Name"/><xsl:text/>
  3145.             </xsl:when>
  3146.             <xsl:when test="$inlineRP and ($renderPattern = 'DisplayPattern')">
  3147.                 <!-- create the Length variable before hand, using xslt string function-->
  3148.                 <xsl:apply-templates select="$inlineRP//Length | $inlineRP//Field" mode="genVariables">
  3149.                     <xsl:with-param name="currentView" select="$Field"/>
  3150.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3151.                 </xsl:apply-templates>
  3152.                 
  3153.                 <xsl:apply-templates mode="genTemplates" select="$inlineRP/*">
  3154.                     <xsl:with-param name="currentView" select="$currentView"/>
  3155.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  3156.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3157.                     <xsl:with-param name="Field" select="$Field"/>
  3158.                     <xsl:with-param name="ThisField" select="."/>
  3159.                 </xsl:apply-templates>
  3160.             </xsl:when>
  3161.             <xsl:when test="$lookupRP">        
  3162.                 <!-- make reference to the @comments  and other needed <column> beforehand-->
  3163.                  <xsl:apply-templates select=" $lookupRP//Column" mode="genParams">
  3164.                     <xsl:with-param name="currentList" select="$lookupRP"/>
  3165.                     <xsl:with-param name="viewNode" select="$fieldData2"/>
  3166.                 </xsl:apply-templates>            
  3167.      
  3168.                 <!-- variable for switch inside recurrence field -->
  3169.                 <xsl:if test="$lookupRP//Switch|$lookupRP//FieldSwitch">
  3170.                     <xsl:apply-templates select="$lookupRP//Switch|$lookupRP//FieldSwitch" mode="genVariablesInField">
  3171.                         <xsl:with-param name="currentView" select="$Field"/>
  3172.                         <xsl:with-param name="fieldData" select="$fieldData"/>
  3173.                         <xsl:with-param name="realFieldData" select="$fieldData2"/>
  3174.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3175.                     </xsl:apply-templates>        
  3176.                 </xsl:if>    
  3177.  
  3178.                 <!-- variable for lookupcolumn inside user field -->
  3179.                 <xsl:if test="$lookupRP//LookupColumn">
  3180.                     <xsl:apply-templates select="$lookupRP//LookupColumn" mode="genVariablesInField">
  3181.                         <xsl:with-param name="currentView" select="$Field"/>
  3182.                         <xsl:with-param name="fieldData" select="$fieldData"/>        
  3183.                         <xsl:with-param name="realFieldData" select="$fieldData2"/>
  3184.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3185.                     </xsl:apply-templates>        
  3186.                 </xsl:if>    
  3187.                 
  3188.                 <!-- create the Limit variable before hand, using xslt string function-->
  3189.                 <xsl:apply-templates select="$lookupRP//Limit" mode="genVariables">
  3190.                     <xsl:with-param name="currentView" select="$Field"/>
  3191.                 </xsl:apply-templates>
  3192.  
  3193.                 <xsl:apply-templates mode="genTemplates" select="$lookupRP/*">
  3194.                     <xsl:with-param name="currentView" select="$currentView"/>
  3195.                     <xsl:with-param name="fieldData" select="$fieldData2"/>
  3196.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3197.                     <xsl:with-param name="Field" select="$Field"/>
  3198.                     <xsl:with-param name="ThisField" select="."/>                    
  3199.                 </xsl:apply-templates>
  3200.             </xsl:when>
  3201.             
  3202.             <xsl:when test="$renderPattern = 'NewPattern'">
  3203.                     <xsl:call-template name="FieldExpandTempl">
  3204.                     <xsl:with-param name="currentView" select="$currentView"/>
  3205.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  3206.                     <xsl:with-param name="renderPattern" select="'EditPattern'"/>
  3207.                     <xsl:with-param name="Field" select="."/>        
  3208.                     <xsl:with-param name="ThisField" select="."/>                                
  3209.                 </xsl:call-template>
  3210.             </xsl:when>
  3211.             <xsl:otherwise>
  3212.                  <span><xz:value-of>
  3213.                     <xsl:attribute name="select">@<xsl:value-of select="$fieldData2/@Name"/>
  3214.                     </xsl:attribute>
  3215.                 </xz:value-of></span>
  3216.             </xsl:otherwise>
  3217.         </xsl:choose>
  3218.  
  3219.     </xsl:template>
  3220.         
  3221.  
  3222.     <!--Inside script, just output the field name.-->
  3223.     <xsl:template mode="genTemplates-inscript" match="Field[@Name]">
  3224.         <xsl:param name="currentView"/>        
  3225.         <xsl:param name="fieldData"/>
  3226.         <xsl:param name="renderPattern"/>
  3227.         <xsl:param name="Field"/>
  3228.         
  3229.         <xsl:text/>{@<xsl:value-of select="@Name"/>}<xsl:text/>
  3230.     </xsl:template>
  3231.  
  3232.     <xsl:template mode="genVariables" match="Field[@Name]">
  3233.         <xsl:param name="currentView"/>
  3234.         <xsl:param name="renderPattern"/>
  3235.             
  3236.         <xsl:if test="ancestor::Field and /List/MetaData/Fields/Field[@Name=current()/@Name][@Type='Lookup' or @Type='Boolean']">
  3237.             <xsl:variable name="type" select="/List/MetaData/Fields/Field[@Name=current()/@Name]/@Type"/>
  3238.             <xz:variable>
  3239.                 <xsl:attribute name="name">Field<xsl:value-of select="generate-id(.)"/></xsl:attribute>
  3240.                     <xsl:apply-templates mode="genTemplates" select="($fldTypes/FieldTypes/FieldType | $fldTypes/List/Data/Rows/Row)[Field[@Name = 'TypeName'] = $type]/RenderPattern[@Name = $renderPattern]/*">
  3241.                         <xsl:with-param name="currentView" select="$currentView"/>
  3242.                         <xsl:with-param name="fieldData" select="."/>
  3243.                         <xsl:with-param name="renderPattern" select="."/>
  3244.                         <xsl:with-param name="Field" select="."/>                        
  3245.                     </xsl:apply-templates>
  3246.             </xz:variable>
  3247.         </xsl:if>
  3248.     </xsl:template>
  3249.  
  3250.     <xsl:template mode="genTemplates" match="Field[@Name]">
  3251.         <xsl:param name="currentView"/>        
  3252.         <xsl:param name="fieldData"/>
  3253.         <xsl:param name="renderPattern"/>
  3254.         <xsl:param name="Field"/>
  3255.  
  3256.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  3257.         <xsl:choose>
  3258.             <xsl:when test="@InAttr='TRUE'">
  3259.                 <xsl:text/>@<xsl:value-of select="@Name"/><xsl:text/>
  3260.             </xsl:when>        
  3261.             <xsl:when test="not(ancestor::Fields)">
  3262.                 <xsl:call-template name="FieldExpandTempl">
  3263.                     <xsl:with-param name="currentView" select="$currentView"/>
  3264.                     <xsl:with-param name="fieldData" select="$fieldData"/>
  3265.                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3266.                     <xsl:with-param name="Field" select="$Field"/>
  3267.                 </xsl:call-template>
  3268.             </xsl:when>
  3269.                         
  3270.             <!--if <html> <ifequal> sequence, we know it's inside a <href> tag. -->
  3271.             <xsl:when test="@StripWS = 'TRUE' or (name(preceding-sibling::*[1])='IfEqual' and name(preceding-sibling::*[2])='HTML') or (name(preceding-sibling::*[1])='HTML' and substring($prevStr, string-length($prevStr), 1)='=' )">
  3272.                 <xsl:text/>{@<xsl:value-of select="@Name"/>}<xsl:text/>            
  3273.             </xsl:when>
  3274.             <xsl:when test="ancestor::ListFormOpening or ancestor::Expr or ancestor::Expr1 or ancestor::Expr2 or ancestor::SetVar or substring($prevStr, string-length($prevStr), 1)='='">
  3275.                 <xsl:text/>@<xsl:value-of select="@Name"/><xsl:text/>
  3276.             </xsl:when>
  3277.             <xsl:when test="ancestor::Field and /List/MetaData/Fields/Field[@Name=current()/@Name]">
  3278.                 <xsl:choose>
  3279.                 <xsl:when test="/List/MetaData/Fields/Field[@Name=current()/@Name][@Type='Lookup' or @Type='Boolean']">
  3280.                     <xsl:text/>{$Field<xsl:value-of select="generate-id(.)"/>}<xsl:text/>
  3281.                 </xsl:when>
  3282.                 <xsl:otherwise>
  3283.                     <xsl:call-template name="FieldExpandTempl">
  3284.                         <xsl:with-param name="currentView" select="$currentView"/>
  3285.                         <xsl:with-param name="fieldData" select="/List/MetaData/Fields/Field[@Name=current()/@Name]"/>
  3286.                         <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3287.                         <xsl:with-param name="Field" select="$Field"/>
  3288.                     </xsl:call-template>
  3289.                 </xsl:otherwise>
  3290.                 </xsl:choose>
  3291.             </xsl:when>
  3292.             <xsl:otherwise>        
  3293.                 <xz:value-of>
  3294.                     <xsl:attribute name="select">@<xsl:value-of select="@Name"/></xsl:attribute>
  3295.                 </xz:value-of>
  3296.             </xsl:otherwise>
  3297.         </xsl:choose>
  3298.     </xsl:template>
  3299.  
  3300.      <!-- generate variables in the header of the view files
  3301.             to get rid of the annoying "alt=ifequal" problem.    -->
  3302.     <xsl:template match="IfEqual" mode="genVariables">
  3303.         <xsl:param name="currentView"/>        
  3304.         <xsl:param name="fieldData"/>
  3305.         <xsl:param name="renderPattern"/>
  3306.         <xsl:param name="Field"/>
  3307.         
  3308.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  3309.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  3310.  
  3311.         <!-- if the previous node is html node that ends with ", we'll do special add the special handlding 
  3312.              code to have var first, then directly call the var in the usage-->
  3313.         <xsl:if test="name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = '"' or name($prevNode) = 'ImagesPath'">
  3314.             <xz:variable>
  3315.                 <xsl:attribute name="name"><xsl:value-of select="generate-id(.)"/></xsl:attribute>
  3316.                 <xz:choose>
  3317.                     <xz:when>
  3318.                         <xsl:attribute name="test">
  3319.                             <xsl:apply-templates mode="genTemplates" select="Expr1/*">
  3320.                                 <xsl:with-param name="currentView" select="$currentView"/>
  3321.                                 <xsl:with-param name="fieldData" select="$fieldData"/>
  3322.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3323.                                 <xsl:with-param name="Field" select="$Field"/>                        
  3324.                             </xsl:apply-templates>
  3325.                             <xsl:text/>=<xsl:text/>
  3326.                             <xsl:choose>
  3327.                                 <xsl:when test="not(Expr2/*)">''</xsl:when>
  3328.                                 <xsl:otherwise>
  3329.                                         <xsl:apply-templates mode="genTemplates" select="Expr2/*">
  3330.                                             <xsl:with-param name="currentView" select="$currentView"/>
  3331.                                             <xsl:with-param name="fieldData" select="$fieldData"/>
  3332.                                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3333.                                             <xsl:with-param name="Field" select="$Field"/>
  3334.                                     </xsl:apply-templates>        
  3335.                                 </xsl:otherwise>
  3336.                             </xsl:choose>                
  3337.                         </xsl:attribute>                                
  3338.                 
  3339.                         <xsl:apply-templates mode="genTemplates" select="Then/*">
  3340.                             <xsl:with-param name="currentView" select="$currentView"/>
  3341.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  3342.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3343.                             <xsl:with-param name="Field" select="$Field"/>                        
  3344.                         </xsl:apply-templates>            
  3345.                     </xz:when>
  3346.                     <xz:otherwise>
  3347.                         <xsl:apply-templates mode="genTemplates" select="Else/*">
  3348.                             <xsl:with-param name="currentView" select="$currentView"/>
  3349.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  3350.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3351.                             <xsl:with-param name="Field" select="$Field"/>                        
  3352.                         </xsl:apply-templates>
  3353.                     </xz:otherwise>
  3354.                 </xz:choose>
  3355.             </xz:variable>
  3356.         </xsl:if>
  3357.     </xsl:template>
  3358.  
  3359.     <xsl:template mode="genTemplates" match="Attachments">
  3360.         <xz:if>
  3361.             <xsl:attribute name="test">not (@Attachments=0)</xsl:attribute>
  3362.                 <img border="0" src="{{$HttpVDir}}/_layouts/images/attach.gif"/>
  3363.         </xz:if>
  3364.     </xsl:template>
  3365.  
  3366.     <xsl:template mode="genTemplates" match="IfEqual">
  3367.         <xsl:param name="currentView"/>        
  3368.         <xsl:param name="fieldData"/>
  3369.         <xsl:param name="renderPattern"/>
  3370.         <xsl:param name="Field"/>
  3371.     
  3372.         <xsl:variable name="prevNode" select="preceding-sibling::*[1]"/>        
  3373.         <xsl:variable name="prevStr"     select="normalize-space(string(preceding-sibling::*[1]))"/>
  3374.  
  3375.         <xsl:choose>
  3376.             <xsl:when test="ancestor::SetVar">true</xsl:when>
  3377.             <xsl:when test="Expr1/GetVar[@Name='ErrorText']">
  3378.                 <xsl:choose>
  3379.                     <xsl:when test="string(Expr2)='TRUE'">
  3380.                         <xsl:apply-templates mode="genTemplates" select="Else/*">
  3381.                             <xsl:with-param name="currentView" select="$currentView"/>
  3382.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  3383.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3384.                             <xsl:with-param name="Field" select="$Field"/>                        
  3385.                         </xsl:apply-templates>                                                            
  3386.                     </xsl:when>
  3387.                     <xsl:otherwise>
  3388.                         <xsl:apply-templates mode="genTemplates" select="Then/*">
  3389.                             <xsl:with-param name="currentView" select="$currentView"/>
  3390.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  3391.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3392.                             <xsl:with-param name="Field" select="$Field"/>                        
  3393.                         </xsl:apply-templates>                                                                                    
  3394.                     </xsl:otherwise>
  3395.                 </xsl:choose>
  3396.             </xsl:when>
  3397.             <xsl:when test="name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = '"' or name($prevNode) = 'ImagesPath'">
  3398.                 <xsl:text/>{$<xsl:value-of select="generate-id(.)"/>}<xsl:text/>
  3399.             </xsl:when>
  3400.             <xsl:otherwise>
  3401.                 <xz:choose>
  3402.                     <xz:when>
  3403.                         <xsl:attribute name="test">
  3404.                             <xsl:apply-templates mode="genTemplates" select="Expr1/*">
  3405.                                 <xsl:with-param name="currentView" select="$currentView"/>
  3406.                                 <xsl:with-param name="fieldData" select="$fieldData"/>
  3407.                                 <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3408.                                 <xsl:with-param name="Field" select="$Field"/>                        
  3409.                             </xsl:apply-templates>
  3410.                             <xsl:text/>=<xsl:text/>
  3411.                             <xsl:choose>
  3412.                                 <xsl:when test="not(Expr2/*)">'<xsl:value-of select="string(Expr2)"/>'</xsl:when>
  3413.                                 <xsl:when test="Expr2/ListUrlDir and Expr2/HTML">
  3414.                                     <xsl:text/>concat(<xsl:for-each select="Expr2/*"><xsl:if test="not(name()='ListUrlDir')">'</xsl:if><xsl:apply-templates mode="genTemplates" select="."/><xsl:if test="not(name()='ListUrlDir')">'</xsl:if><xsl:if test="not(position() = last())">,</xsl:if></xsl:for-each>)<xsl:text/>
  3415.                                 </xsl:when>
  3416.                                 <xsl:otherwise>
  3417.                                 <xsl:apply-templates mode="genTemplates" select="Expr2/*">
  3418.                                     <xsl:with-param name="currentView" select="$currentView"/>
  3419.                                     <xsl:with-param name="fieldData" select="$fieldData"/>
  3420.                                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3421.                                     <xsl:with-param name="Field" select="$Field"/>                        
  3422.                                 </xsl:apply-templates>        
  3423.                                 </xsl:otherwise>
  3424.                             </xsl:choose>                
  3425.                         </xsl:attribute>
  3426.  
  3427.                         <xsl:choose>
  3428.                             <xsl:when test="Then/*">
  3429.                                 <xsl:apply-templates mode="genTemplates" select="Then/*">
  3430.                                     <xsl:with-param name="currentView" select="$currentView"/>
  3431.                                     <xsl:with-param name="fieldData" select="$fieldData"/>
  3432.                                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3433.                                     <xsl:with-param name="Field" select="$Field"/>                        
  3434.                                 </xsl:apply-templates>                                    
  3435.                             </xsl:when>
  3436.                             <xsl:otherwise>
  3437.                                 <xsl:value-of select="Then"/>                                
  3438.                             </xsl:otherwise>
  3439.                         </xsl:choose>
  3440.                     </xz:when>
  3441.                     <xz:otherwise>                    
  3442.                         <xsl:choose>
  3443.                             <xsl:when test="Else/*">
  3444.                                 <xsl:apply-templates mode="genTemplates" select="Else/*">
  3445.                                     <xsl:with-param name="currentView" select="$currentView"/>
  3446.                                     <xsl:with-param name="fieldData" select="$fieldData"/>
  3447.                                     <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3448.                                     <xsl:with-param name="Field" select="$Field"/>                        
  3449.                                 </xsl:apply-templates>                                    
  3450.                             </xsl:when>
  3451.                             <xsl:otherwise>
  3452.                                 <xsl:value-of select="Else"/>        
  3453.                             </xsl:otherwise>
  3454.                         </xsl:choose>
  3455.                     </xz:otherwise>
  3456.                 </xz:choose>        
  3457.             </xsl:otherwise>
  3458.         </xsl:choose>
  3459.     </xsl:template>
  3460.  
  3461.     <xsl:template mode="genTemplates" match="CurrentRights">
  3462.         <xsl:text>{ddwrt:CurrentRights()}</xsl:text>
  3463.     </xsl:template>
  3464.     
  3465.     <!-- keep in sync with global.cs!!!
  3466.         EmptyMask               =0x0000000000000000,
  3467.  
  3468.         // list/document perms  =0x000000000000XXXX,
  3469.         ViewListItems           =0x0000000000000001,
  3470.         AddListItems            =0x0000000000000002,
  3471.         EditListItems           =0x0000000000000004,
  3472.         DeleteListItems         =0x0000000000000008,
  3473.         ApproveItems            =0x0000000000000010,
  3474.         OpenItems               =0x0000000000000020,
  3475.         ViewVersions            =0x0000000000000040,
  3476.         DeleteVersions          =0x0000000000000080,
  3477.         CancelCheckout          =0x0000000000000100,
  3478.         ManagePersonalViews     =0x0000000000000200,
  3479.         // UnusedList10         =0x0000000000000400, /* obsolete ManageListPermission */
  3480.         ManageLists             =0x0000000000000800,
  3481.         ViewFormPages           =0x0000000000001000,
  3482.         // UnusedList20         =0x0000000000002000,
  3483.         // UnusedList40         =0x0000000000004000,
  3484.         // UnusedList80         =0x0000000000008000,
  3485.  
  3486.         // web level perms      =0x0000XXXXXXXX0000,
  3487.         Open                    =0x0000000000010000,
  3488.         ViewPages               =0x0000000000020000,
  3489.         AddAndCustomizePages    =0x0000000000040000,
  3490.         ApplyThemeAndBorder     =0x0000000000080000,
  3491.         ApplyStyleSheets        =0x0000000000100000,
  3492.         ViewUsageData           =0x0000000000200000,
  3493.         CreateSSCSite           =0x0000000000400000,
  3494.         ManageSubwebs           =0x0000000000800000,
  3495.         CreateGroups            =0x0000000001000000,
  3496.         ManagePermissions       =0x0000000002000000,
  3497.         BrowseDirectories       =0x0000000004000000,
  3498.         BrowseUserInfo          =0x0000000008000000,
  3499.         AddDelPrivateWebParts   =0x0000000010000000,
  3500.         UpdatePersonalWebParts  =0x0000000020000000,
  3501.         ManageWeb               =0x0000000040000000,
  3502.         UseRemoteAPIs           =0x0000002000000000,
  3503.         ManageAlerts            =0x0000004000000000,
  3504.         CreateAlerts            =0x0000008000000000,
  3505.         EditMyUserInfo          =0x0000010000000000,
  3506.         
  3507.         // special perms        =0xXXXX000000000000,
  3508.         EnumeratePermissions    =0x4000000000000000,
  3509.  
  3510.         // end of list
  3511.         FullMask                =0x7FFFFFFFFFFFFFFF,
  3512.     -->
  3513.     <xsl:template name="GetPermissionMask">
  3514.     
  3515.         <xsl:variable name="Permission" select="name(@*[1])"/>
  3516.         
  3517.         <xsl:choose>
  3518.             <xsl:when test="$Permission='PermEmptyMask'">0</xsl:when>
  3519.             <xsl:when test="$Permission='PermViewListItems'">1</xsl:when>
  3520.             <xsl:when test="$Permission='PermAddListItems'">2</xsl:when>
  3521.             <xsl:when test="$Permission='PermEditListItems'">4</xsl:when>
  3522.             <xsl:when test="$Permission='PermDeleteListItems'">8</xsl:when>
  3523.             <xsl:when test="$Permission='PermApproveItems'">16</xsl:when>
  3524.             <xsl:when test="$Permission='PermOpenItems'">32</xsl:when>
  3525.             <xsl:when test="$Permission='PermViewVersions'">64</xsl:when>
  3526.             <xsl:when test="$Permission='PermDeleteVersions'">128</xsl:when>
  3527.             <xsl:when test="$Permission='PermCancelCheckout'">256</xsl:when>
  3528.             <xsl:when test="$Permission='PermManagePersonalViews'">512</xsl:when>
  3529.             <xsl:when test="$Permission='PermManageLists'">2048</xsl:when>
  3530.             <xsl:when test="$Permission='PermViewFormPages'">4096</xsl:when>
  3531.             <xsl:when test="$Permission='PermOpen'">65536</xsl:when>
  3532.             <xsl:when test="$Permission='PermViewPages'">131072</xsl:when>
  3533.             <xsl:when test="$Permission='PermAddAndCustomizePages'">262144</xsl:when>
  3534.             <xsl:when test="$Permission='PermApplyThemeAndBorder'">524288</xsl:when>
  3535.             <xsl:when test="$Permission='PermApplyStyleSheets'">1048576</xsl:when>
  3536.             <xsl:when test="$Permission='PermViewUsageData'">2097152</xsl:when>
  3537.             <xsl:when test="$Permission='PermCreateSSCSite'">4194314</xsl:when>
  3538.             <xsl:when test="$Permission='PermManageSubwebs'">8388608</xsl:when>
  3539.             <xsl:when test="$Permission='PermCreateGroups'">16777216</xsl:when>
  3540.             <xsl:when test="$Permission='PermManagePermissions'">33554432</xsl:when>
  3541.             <xsl:when test="$Permission='PermBrowseDirectories'">67108864</xsl:when>
  3542.             <xsl:when test="$Permission='PermBrowseUserInfo'">134217728</xsl:when>
  3543.             <xsl:when test="$Permission='PermAddDelPrivateWebParts'">268435456</xsl:when>
  3544.             <xsl:when test="$Permission='PermUpdatePersonalWebParts'">536870912</xsl:when>
  3545.             <xsl:when test="$Permission='PermManageWeb'">1073741824</xsl:when>
  3546.             <xsl:when test="$Permission='PermUseRemoteAPIs'">137438953472</xsl:when>
  3547.             <xsl:when test="$Permission='PermManageAlerts'">274877906944</xsl:when>
  3548.             <xsl:when test="$Permission='PermCreateAlerts'">549755813888</xsl:when>
  3549.             <xsl:when test="$Permission='PermEditMyUserInfo'">1099511627776</xsl:when>
  3550.             <xsl:when test="$Permission='PermEnumeratePermissions'">4611686018427387904</xsl:when>
  3551.             <xsl:when test="$Permission='PermFullMask'">9223372036854775807</xsl:when>
  3552.             <xsl:otherwise>0</xsl:otherwise>
  3553.         </xsl:choose>
  3554.     </xsl:template>
  3555.  
  3556.     <!-- placeholder IfHasRights template that always transforms to the "Then" case -->
  3557.     <xsl:template mode="genTemplates" match="IfHasRights">
  3558.         <xsl:param name="currentView"/>        
  3559.         <xsl:param name="fieldData"/>
  3560.         <xsl:param name="renderPattern"/>
  3561.         <xsl:param name="Field"/>
  3562.         
  3563.         <xz:choose>
  3564.             <xz:when>
  3565.                 <xsl:attribute name="test">ddwrt:IfHasRights(<xsl:for-each select="RightsChoices/*"><xsl:call-template name="GetPermissionMask"/><xsl:if test="not(position()=last())"> + </xsl:if></xsl:for-each>)</xsl:attribute>
  3566.                 <xsl:choose>
  3567.                     <xsl:when test="Then/*">
  3568.                         <xsl:apply-templates mode="genTemplates" select="Then/*">
  3569.                             <xsl:with-param name="currentView" select="$currentView"/>
  3570.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  3571.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3572.                             <xsl:with-param name="Field" select="$Field"/>                        
  3573.                         </xsl:apply-templates>
  3574.                     </xsl:when>
  3575.                     <xsl:otherwise>
  3576.                         <xsl:value-of select="Then"/>
  3577.                     </xsl:otherwise>
  3578.                 </xsl:choose>
  3579.             </xz:when>
  3580.             <xz:otherwise>
  3581.                 <xsl:choose>
  3582.                     <xsl:when test="Else/*">
  3583.                         <xsl:apply-templates mode="genTemplates" select="Else/*">
  3584.                             <xsl:with-param name="currentView" select="$currentView"/>
  3585.                             <xsl:with-param name="fieldData" select="$fieldData"/>
  3586.                             <xsl:with-param name="renderPattern" select="$renderPattern"/>
  3587.                             <xsl:with-param name="Field" select="$Field"/>                        
  3588.                         </xsl:apply-templates>
  3589.                     </xsl:when>
  3590.                     <xsl:otherwise>
  3591.                         <xsl:value-of select="Else"/>
  3592.                     </xsl:otherwise>
  3593.                 </xsl:choose>                
  3594.             </xz:otherwise>
  3595.         </xz:choose>
  3596.     </xsl:template>
  3597.  
  3598.     <xsl:template name="ProperEscapedApostrophe">
  3599.         <xsl:variable name="prevNode" select="ancestor::ScriptQuote/preceding-sibling::*[1]"/>
  3600.         <xsl:variable name="prevStr" select="normalize-space(string(ancestor::ScriptQuote/preceding-sibling::*[1]))" />
  3601.         
  3602.         <xsl:choose>
  3603.             <xsl:when test="name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = "'"">
  3604.                 <xsl:text disable-output-escaping="yes">&quot;</xsl:text>
  3605.             </xsl:when>
  3606.             <xsl:when test="name($prevNode) = 'HTML' and substring($prevStr, string-length($prevStr), 1) = '"'">
  3607.                 <xsl:text disable-output-escaping="yes">&apos;</xsl:text>
  3608.             </xsl:when>
  3609.             <xsl:otherwise>'</xsl:otherwise>
  3610.         </xsl:choose>
  3611.     </xsl:template>
  3612. </xsl:stylesheet>